drg_cms 0.5.3 → 0.5.5
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.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/drg_cms/drg_cms.css +5 -0
- data/app/forms/dc_big_table.yml +3 -1
- data/app/helpers/cmsedit_helper.rb +16 -0
- data/app/helpers/dc_application_helper.rb +44 -8
- data/app/helpers/dc_simple_menu_renderer.rb +14 -5
- data/config/locales/models_en.yml +1 -1
- data/lib/drg_cms/version.rb +1 -1
- data/lib/tasks/database.rake +93 -0
- data/lib/tasks/dc_at_the_beginning.rake +0 -2
- data/lib/tasks/tests.rake +22 -0
- metadata +4 -17
- data/lib/examples/extend_database_model/dc_user.rb +0 -19
- data/lib/examples/extend_database_model/dc_user.yml +0 -11
- data/lib/examples/extend_database_model/locale_en.yml +0 -13
- data/lib/examples/extend_database_model/locale_sl.yml +0 -13
- data/lib/examples/image gallery/gallery.yml +0 -58
- data/lib/examples/image gallery/gallery_renderer.rb +0 -74
- data/lib/examples/picture gallery/gallery_renderer.rb +0 -74
- data/lib/examples/responsive/design.erb +0 -35
- data/lib/examples/responsive/mailing.rb +0 -32
- data/lib/examples/responsive/responsive.css +0 -27
- data/lib/examples/responsive/responsive_controller.rb +0 -56
- data/lib/examples/responsive/responsive_renderer.rb +0 -104
- data/lib/examples/responsive/responsive_views/_send_mail.erb +0 -4
- data/lib/tasks/at_the_beginning.yml +0 -26
- data/lib/tasks/send_mail.rake +0 -253
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0867ef411e20c533abaff83ba61268fffe01be0d
|
4
|
+
data.tar.gz: 7a249dfea4847991e8437fd9f5b9d9f0445cedd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52bf2980ec6fbc9c88314b21b766fa827ec6e482dbf9db06b0d029adec3d4759b5157de196aef1c717ec1c2ac8016f5b9479b3d341fb716ac841f38957360670
|
7
|
+
data.tar.gz: aced1888c2df9660b106ba36129db5b9eaffb94ff7fae741fd845ac3e665946c5a6e510d37c8c86024870caf8590e93b5300d48a5ef9ca53dcc90f1f6cb4f303
|
data/app/forms/dc_big_table.yml
CHANGED
@@ -609,6 +609,18 @@ def dc_check_and_default(value, default, values=nil) #:nodoc:
|
|
609
609
|
value
|
610
610
|
end
|
611
611
|
|
612
|
+
############################################################################
|
613
|
+
# Creates top or bottom horizontal line on form.
|
614
|
+
############################################################################
|
615
|
+
def top_bottom_line(yaml)
|
616
|
+
if yaml.class == Hash
|
617
|
+
clas = yaml['class']
|
618
|
+
style = yaml['style']
|
619
|
+
end
|
620
|
+
clas ||= 'dc-separator'
|
621
|
+
"<tr><td colspan=\"4\" class=\"#{clas}\" style=\"#{style}\"></td></tr>"
|
622
|
+
end
|
623
|
+
|
612
624
|
############################################################################
|
613
625
|
# Creates input field for one tab. Subroutine of dc_fields_for_form.
|
614
626
|
############################################################################
|
@@ -654,6 +666,9 @@ def dc_fields_for_tab(fields) #:nodoc:
|
|
654
666
|
else # litle error string
|
655
667
|
"Error: Code for field type #{options['type']} not defined!"
|
656
668
|
end
|
669
|
+
# Separator
|
670
|
+
html << top_bottom_line(options['top-line']) if options['top-line']
|
671
|
+
# Double entry fields in one row
|
657
672
|
double_field = 1 if options['double']
|
658
673
|
html << '<tr>' if double_field < 2
|
659
674
|
#
|
@@ -672,6 +687,7 @@ def dc_fields_for_tab(fields) #:nodoc:
|
|
672
687
|
html << '</tr>' if double_field != 1
|
673
688
|
double_field = 0 if double_field == 2
|
674
689
|
double_field = 2 if double_field == 1
|
690
|
+
html << top_bottom_line(options['bottom-line']) if options['bottom-line']
|
675
691
|
end
|
676
692
|
html << '</table></table>'
|
677
693
|
end
|
@@ -933,16 +933,17 @@ def dc_user_has_role( role, user=nil, roles=nil )
|
|
933
933
|
end
|
934
934
|
|
935
935
|
####################################################################
|
936
|
-
# Returns true if parameter has value of 0, false, no or -. Returns default
|
936
|
+
# Returns true if parameter has value of 0, false, no, none or -. Returns default
|
937
937
|
# if parameter has nil value.
|
938
938
|
#
|
939
939
|
# Parameters:
|
940
|
-
# [what] String/boolean.
|
940
|
+
# [what] String/boolean/Integer.
|
941
941
|
# [default] Default value when what has value of nil. False by default.
|
942
942
|
#
|
943
943
|
# Example:
|
944
|
-
# dc_dont?('
|
945
|
-
# dc_dont?(
|
944
|
+
# dc_dont?('none') # => true
|
945
|
+
# dc_dont?('-') # => true
|
946
|
+
# dc_dont?(1) # => false
|
946
947
|
####################################################################
|
947
948
|
def dc_dont?(what, default=false)
|
948
949
|
return default if what.nil?
|
@@ -1011,11 +1012,8 @@ def dc_big_table(key)
|
|
1011
1012
|
end
|
1012
1013
|
|
1013
1014
|
########################################################################
|
1014
|
-
# Will return html code required for open edit form in iframe. If parameters
|
1015
|
-
# are found in url iframe will be initial loaded with url parameters thus
|
1016
|
-
# enabling forms load on page display.
|
1017
1015
|
########################################################################
|
1018
|
-
def iframe_edit1()
|
1016
|
+
def iframe_edit1() #:nodoc
|
1019
1017
|
# default_table = params[:table] if default_table.nil?
|
1020
1018
|
# p params
|
1021
1019
|
parms = {}
|
@@ -1035,4 +1033,42 @@ def iframe_edit1()
|
|
1035
1033
|
ret.html_safe
|
1036
1034
|
end
|
1037
1035
|
|
1036
|
+
########################################################################
|
1037
|
+
# Will return html code required for load DRG form into iframe. If parameters
|
1038
|
+
# are passed to method iframe url will have initial value and thus enabling automatic form
|
1039
|
+
# load on page display.
|
1040
|
+
#
|
1041
|
+
# Parameters:
|
1042
|
+
# [table] String: Collection (table) name used to load initial form.
|
1043
|
+
# [opts] Hash: Optional parameters which define url for loading DRG form.
|
1044
|
+
# These parameters are :action, :oper, :table, :formname, :id, :readonly
|
1045
|
+
#
|
1046
|
+
# Example:
|
1047
|
+
# # just iframe code
|
1048
|
+
# <%= dc_iframe_edit(nil) %>
|
1049
|
+
# # load note form for note collection
|
1050
|
+
# <%= dc_iframe_edit('note') %>
|
1051
|
+
# # on register collection use reg_adresses formname to display data with id @register.id
|
1052
|
+
# <%= dc_iframe_edit('register', action: :show, formname: 'reg_adresses', readonly: 1, id: @register.id ) %>
|
1053
|
+
#
|
1054
|
+
# Returns:
|
1055
|
+
# Html code for edit iframe
|
1056
|
+
########################################################################
|
1057
|
+
def dc_iframe_edit(table, opts={})
|
1058
|
+
ret = if params.size > 2 and table # controller, action, path is minimal
|
1059
|
+
params[:controller] = 'cmsedit'
|
1060
|
+
params[:action] = (params[:oper] and (params[:oper] == 'edit')) ? 'edit' : 'index'
|
1061
|
+
params[:action] = opts[:action] unless params[:oper]
|
1062
|
+
params[:table] ||= table
|
1063
|
+
params[:formname] ||= opts[:formname] || table
|
1064
|
+
params[:id] ||= params[:idp] || opts[:id]
|
1065
|
+
params[:readonly] ||= opts[:readonly]
|
1066
|
+
params[:path] = nil
|
1067
|
+
"<iframe id='iframe_edit' name='iframe_edit' src='#{url_for params}'></iframe>"
|
1068
|
+
else
|
1069
|
+
"<iframe id='iframe_edit' name='iframe_edit'></iframe>"
|
1070
|
+
end
|
1071
|
+
ret.html_safe
|
1072
|
+
end
|
1073
|
+
|
1038
1074
|
end
|
@@ -98,12 +98,21 @@ def link_4menu(item)
|
|
98
98
|
link = '/' + link unless link[0] == '/' # link should start with '/'
|
99
99
|
end
|
100
100
|
|
101
|
-
|
101
|
+
caption = ''
|
102
|
+
unless item.picture.blank?
|
103
|
+
caption = if item.picture.match(/\./)
|
104
|
+
@parent.image_tag(item.picture)
|
105
|
+
elsif item.picture.match('<i')
|
106
|
+
item.picture
|
107
|
+
else
|
108
|
+
@parent.fa_icon(item.picture)
|
109
|
+
end
|
110
|
+
end
|
102
111
|
# - in first place won't write caption text
|
103
|
-
caption = item.caption[0] == '-' ? '' : item.caption
|
104
|
-
|
105
|
-
|
106
|
-
|
112
|
+
caption = caption.html_safe + (item.caption[0] == '-' ? '' : (' ' + item.caption) )
|
113
|
+
|
114
|
+
target = item.target.blank? ? nil : item.target
|
115
|
+
@parent.link_to(caption, link, {target: target})
|
107
116
|
end
|
108
117
|
|
109
118
|
########################################################################
|
@@ -491,7 +491,7 @@ en:
|
|
491
491
|
page_table: Name of table holding data for pages
|
492
492
|
page_class: Rails model class name which defines table holding pages data usually DcPage
|
493
493
|
menu_class: Rails model class name which defines table holding menu data usually DcMenu
|
494
|
-
site_layout: Rails layout used to draw response. This is by default
|
494
|
+
site_layout: Rails layout used to draw response. This is by default content layout.
|
495
495
|
files_directory: Directory name where uploaded files are located
|
496
496
|
logo: Logotype picture for the site
|
497
497
|
dc_policies: Access policies defined for the site
|
data/lib/drg_cms/version.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
@logger = Logger.new(STDOUT)
|
3
|
+
|
4
|
+
#########################################################################
|
5
|
+
# Determine module class from filename.
|
6
|
+
#########################################################################
|
7
|
+
def determine_model(path)
|
8
|
+
path =~ /(.*)\/(.*).rb/
|
9
|
+
begin
|
10
|
+
$2.camelize.constantize
|
11
|
+
rescue Exception # it happends
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#########################################################################
|
17
|
+
# Create index for single module
|
18
|
+
#########################################################################
|
19
|
+
def create_index(model)
|
20
|
+
return if model.index_specifications.empty?
|
21
|
+
#
|
22
|
+
if !model.embedded? || model.cyclic?
|
23
|
+
@logger.info("DRGCMS: Creating indexes on #{model}:")
|
24
|
+
model.create_indexes
|
25
|
+
model.index_specifications.each do |spec|
|
26
|
+
@logger.info("DRGCMS: Index: #{spec.key}, Options: #{spec.options}")
|
27
|
+
end
|
28
|
+
model
|
29
|
+
else
|
30
|
+
@logger.info("DRGCMS: Index ignored on: #{model}, please define in the root model.")
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#########################################################################
|
36
|
+
# Will remove all undefined indexes from collection.
|
37
|
+
#########################################################################
|
38
|
+
def remove_undefined_indexes(model)
|
39
|
+
return if model.embedded?
|
40
|
+
#
|
41
|
+
begin
|
42
|
+
undefined = []
|
43
|
+
model.collection.indexes.each do |index|
|
44
|
+
# ignore default index
|
45
|
+
next if index['name'] == '_id_'
|
46
|
+
|
47
|
+
key = index['key'].symbolize_keys
|
48
|
+
spec = model.index_specification(key)
|
49
|
+
undefined << index unless spec
|
50
|
+
end
|
51
|
+
rescue Mongo::Error::OperationFailure; end
|
52
|
+
#
|
53
|
+
undefined.each do |index|
|
54
|
+
key = index['key'].symbolize_keys
|
55
|
+
collection = model.collection
|
56
|
+
collection.indexes.drop(key)
|
57
|
+
@logger.info(
|
58
|
+
"MONGOID: Removed index '#{index['name']}' on collection " +
|
59
|
+
"'#{collection.name}' in database '#{collection.database.name}'."
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#########################################################################
|
65
|
+
# Return array of all models found in application.
|
66
|
+
#########################################################################
|
67
|
+
def all_models()
|
68
|
+
models = []
|
69
|
+
DrgCms.paths(:forms).each do |path|
|
70
|
+
models_dir = File.expand_path("../models", path)
|
71
|
+
Dir["#{models_dir}/*.rb"].each do |model_file|
|
72
|
+
model = determine_model(model_file)
|
73
|
+
models << model if !model.nil? and model.respond_to?(:index_specifications)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
models
|
77
|
+
end
|
78
|
+
|
79
|
+
#########################################################################
|
80
|
+
#
|
81
|
+
#########################################################################
|
82
|
+
namespace :drg_cms do
|
83
|
+
desc "Create indexes for all mongoid models. Including those in gem plugins."
|
84
|
+
task :create_indexes => :environment do
|
85
|
+
all_models.each {|model| create_index(model)}
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Remove undefined indexes for all mongoid models. Including those in gem plugins."
|
89
|
+
task :remove_undefined_indexes => :environment do
|
90
|
+
all_models.each {|model| remove_undefined_indexes(model)}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -2,11 +2,9 @@
|
|
2
2
|
#
|
3
3
|
#########################################################################
|
4
4
|
def ok_to_start
|
5
|
-
p 'bla'
|
6
5
|
# DcPermission.all.delete
|
7
6
|
# DcPolicyRole.all.delete
|
8
7
|
# DcUser.all.delete
|
9
|
-
p DcPermission.all.to_a
|
10
8
|
if DcPermission.all.to_a.size > 0
|
11
9
|
p 'DcPermission (Permissions) collection is not empty! Aborting.'
|
12
10
|
return false
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#########################################################################
|
4
|
+
#
|
5
|
+
#########################################################################
|
6
|
+
namespace :drg_cms do
|
7
|
+
|
8
|
+
desc "Runs all tests in test folder"
|
9
|
+
task :test do
|
10
|
+
require 'rake/testtask'
|
11
|
+
require 'rails/test_unit/sub_test_task'
|
12
|
+
|
13
|
+
# p 1, Rake.application.top_level_tasks
|
14
|
+
# p 2, Rails::TestTask.test_creator(Rake.application.top_level_tasks)
|
15
|
+
# Rails::TestTask.test_creator(Rake.application.top_level_tasks).invoke_rake_task
|
16
|
+
|
17
|
+
Rails::TestTask.new(functionals: "test:prepare") do |t|
|
18
|
+
t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drg_cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damjan Rems
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -281,27 +281,14 @@ files:
|
|
281
281
|
- lib/drg_cms.rb
|
282
282
|
- lib/drg_cms/engine.rb
|
283
283
|
- lib/drg_cms/version.rb
|
284
|
-
- lib/examples/extend_database_model/dc_user.rb
|
285
|
-
- lib/examples/extend_database_model/dc_user.yml
|
286
|
-
- lib/examples/extend_database_model/locale_en.yml
|
287
|
-
- lib/examples/extend_database_model/locale_sl.yml
|
288
|
-
- lib/examples/image gallery/gallery.yml
|
289
|
-
- lib/examples/image gallery/gallery_renderer.rb
|
290
|
-
- lib/examples/picture gallery/gallery_renderer.rb
|
291
|
-
- lib/examples/responsive/design.erb
|
292
|
-
- lib/examples/responsive/mailing.rb
|
293
|
-
- lib/examples/responsive/responsive.css
|
294
|
-
- lib/examples/responsive/responsive_controller.rb
|
295
|
-
- lib/examples/responsive/responsive_renderer.rb
|
296
|
-
- lib/examples/responsive/responsive_views/_send_mail.erb
|
297
284
|
- lib/generators/new_drg_form/USAGE
|
298
285
|
- lib/generators/new_drg_form/new_drg_form_generator.rb
|
299
|
-
- lib/tasks/
|
286
|
+
- lib/tasks/database.rake
|
300
287
|
- lib/tasks/dc_at_the_beginning.rake
|
301
288
|
- lib/tasks/dc_cleanup.rake
|
302
289
|
- lib/tasks/log_statistics.rb
|
303
|
-
- lib/tasks/send_mail.rake
|
304
290
|
- lib/tasks/site_statistics.rake
|
291
|
+
- lib/tasks/tests.rake
|
305
292
|
- test/drg_cms_test.rb
|
306
293
|
- test/dummy/README.rdoc
|
307
294
|
- test/dummy/Rakefile
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require_dependency DrgCms.model 'dc_user'
|
2
|
-
|
3
|
-
class DcUser
|
4
|
-
include DcUserConcern
|
5
|
-
|
6
|
-
field :member, type: Boolean, default: false
|
7
|
-
field :card_number, type: String
|
8
|
-
|
9
|
-
index( { 'card_number' => 1 } )
|
10
|
-
|
11
|
-
validate :my_control
|
12
|
-
|
13
|
-
def my_control
|
14
|
-
if member and card_number.to_s.size < 8
|
15
|
-
errors.add(:card_number, "Card number is not valid!")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
table: dc_part
|
2
|
-
index:
|
3
|
-
actions:
|
4
|
-
1: new
|
5
|
-
|
6
|
-
result_set:
|
7
|
-
actions: standard
|
8
|
-
|
9
|
-
columns:
|
10
|
-
1:
|
11
|
-
name: name
|
12
|
-
2:
|
13
|
-
name: div_id
|
14
|
-
3:
|
15
|
-
name: updated_by
|
16
|
-
eval: dc_name4_id,dc_user,name
|
17
|
-
4:
|
18
|
-
name: updated_at
|
19
|
-
|
20
|
-
form:
|
21
|
-
actions: standard
|
22
|
-
title:
|
23
|
-
new: New image
|
24
|
-
edit: Edit image
|
25
|
-
field: name
|
26
|
-
fields:
|
27
|
-
05:
|
28
|
-
name: div_id
|
29
|
-
type: readonly
|
30
|
-
html:
|
31
|
-
size: 10
|
32
|
-
10:
|
33
|
-
name: name
|
34
|
-
type: text_field
|
35
|
-
text: Image title
|
36
|
-
html:
|
37
|
-
size: 50
|
38
|
-
20:
|
39
|
-
name: description
|
40
|
-
type: text_field
|
41
|
-
text: Image description
|
42
|
-
html:
|
43
|
-
size: 50
|
44
|
-
30:
|
45
|
-
name: thumbnail
|
46
|
-
type: file_select
|
47
|
-
html:
|
48
|
-
size: 50
|
49
|
-
40:
|
50
|
-
name: picture
|
51
|
-
type: file_select
|
52
|
-
html:
|
53
|
-
size: 50
|
54
|
-
60:
|
55
|
-
name: order
|
56
|
-
type: text_field
|
57
|
-
html:
|
58
|
-
size: 2
|
@@ -1,74 +0,0 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
#--
|
3
|
-
# Copyright (c) 2014+ Damjan Rems
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
#++
|
24
|
-
|
25
|
-
########################################################################
|
26
|
-
#
|
27
|
-
########################################################################
|
28
|
-
class GalleryRenderer < DcRenderer
|
29
|
-
|
30
|
-
#######################################################################
|
31
|
-
# Will render picture gallery
|
32
|
-
#######################################################################
|
33
|
-
def gallery(page=nil)
|
34
|
-
page ||= @parent.page
|
35
|
-
return '' if page.gallery.blank?
|
36
|
-
#
|
37
|
-
html = '<div class="picture-gallery">'
|
38
|
-
if @parent.dc_edit_mode?
|
39
|
-
opts = { controller: 'cmsedit', action: 'create', formname: 'gallery',
|
40
|
-
table: "#{@parent.site.page_table};dc_part", ids: page._id,
|
41
|
-
'dc_part.div_id' => page.gallery, 'dc_part.name' => page.subject,
|
42
|
-
title: 'Add new picture to gallery.' }
|
43
|
-
html << @parent.dc_link_for_create(opts)
|
44
|
-
end
|
45
|
-
html << '<h2>Picture gallery:</h2>'
|
46
|
-
page.dc_parts.where(:div_id => page.gallery).order(order: 1).each do |part|
|
47
|
-
html << '<span class="gallery-pic">'
|
48
|
-
if @parent.dc_edit_mode?
|
49
|
-
opts.merge!({ action: 'edit', ids: page._id, id: part._id, title: 'Edit picture.' })
|
50
|
-
html << @parent.dc_link_for_edit(opts)
|
51
|
-
end
|
52
|
-
# Display thumbnail if defined. Otherwise use picture. Picture height should be limited by CSS
|
53
|
-
pic = part.thumbnail.blank? ? part.picture : part.thumbnail
|
54
|
-
# Use part.name as title. If not use page title (subject) field
|
55
|
-
title = part.name.blank? ? page.subject : part.name
|
56
|
-
html << @parent.link_to(@parent.image_tag(pic, title: title), part.picture)
|
57
|
-
# Description under picture
|
58
|
-
html << "<h6>#{part.description}</h6>" unless part.description.blank?
|
59
|
-
html << '</span>'
|
60
|
-
end
|
61
|
-
# At the end we use baguetteBox javascript library to transparently display gallery on phone or pc
|
62
|
-
html << @parent.javascript_tag( "baguetteBox.run('.picture-gallery', {});" )
|
63
|
-
html << '</div>'
|
64
|
-
end
|
65
|
-
|
66
|
-
########################################################################
|
67
|
-
#
|
68
|
-
########################################################################
|
69
|
-
def render_html
|
70
|
-
method = @opts[:method] || 'default'
|
71
|
-
respond_to?(method) ? send(method) : "#{self.class}. Method #{method} not found!"
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
#--
|
3
|
-
# Copyright (c) 2014+ Damjan Rems
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
#++
|
24
|
-
|
25
|
-
########################################################################
|
26
|
-
#
|
27
|
-
########################################################################
|
28
|
-
class GalleryRenderer < DcRenderer
|
29
|
-
|
30
|
-
#######################################################################
|
31
|
-
# Will render picture gallery
|
32
|
-
#######################################################################
|
33
|
-
def gallery(page=nil)
|
34
|
-
page = @parent.page if page.nil?
|
35
|
-
return '' if page.gallery.blank?
|
36
|
-
#
|
37
|
-
html = '<div class="picture-gallery">'
|
38
|
-
if @parent.dc_edit_mode?
|
39
|
-
opts = { controller: 'cmsedit', action: 'create', formname: 'gallery',
|
40
|
-
table: "#{@parent.site.page_table};dc_part", ids: page._id,
|
41
|
-
'dc_part.div_id' => page.gallery, 'dc_part.name' => page.subject,
|
42
|
-
title: 'Add new picture to gallery.' }
|
43
|
-
html << @parent.dc_link_for_create(opts)
|
44
|
-
end
|
45
|
-
html << '<h2>Picture gallery:</h2>'
|
46
|
-
page.dc_parts.where(:div_id => page.gallery).order(order: 1).each do |part|
|
47
|
-
html << '<span class="gallery-pic">'
|
48
|
-
if @parent.dc_edit_mode?
|
49
|
-
opts.merge!({ action: 'edit', ids: page._id, id: part._id, title: 'Edit picture.' })
|
50
|
-
html << @parent.dc_link_for_edit(opts)
|
51
|
-
end
|
52
|
-
# Display thumbnail if defined. Otherwise use picture. Picture height should be limited by CSS
|
53
|
-
pic = part.thumbnail.blank? ? part.picture : part.thumbnail
|
54
|
-
# Use part.name as title. If not use page title (subject) field
|
55
|
-
title = part.name.blank? ? page.subject : part.name
|
56
|
-
html << @parent.link_to(@parent.image_tag(pic, title: title), part.picture)
|
57
|
-
# Description under picture
|
58
|
-
html << "<h6>#{part.description}</h6>" unless part.description.blank?
|
59
|
-
html << '</span>'
|
60
|
-
end
|
61
|
-
# At the end we use baguetteBox javascript library to transparently display gallery on phone or pc
|
62
|
-
html << @parent.javascript_tag( "baguetteBox.run('.picture-gallery', {});" )
|
63
|
-
html << '</div>'
|
64
|
-
end
|
65
|
-
|
66
|
-
########################################################################
|
67
|
-
#
|
68
|
-
########################################################################
|
69
|
-
def render_html
|
70
|
-
method = @opts[:method] || 'default'
|
71
|
-
respond_to?(method) ? send(method) : "#{self.class}. Method #{method} not found!"
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
<!-- dc_site.design field data -->
|
2
|
-
<div id="site">
|
3
|
-
<ul id='meni-site' class='small-block-grid-3'>
|
4
|
-
<%= dc_render(:dc_simple_menu, name: 'meni-site', method: 'as_responsive') %>
|
5
|
-
</ul>
|
6
|
-
|
7
|
-
<div class="site-top picture-top">
|
8
|
-
<img src="/files/logos/top-bg-pic.jpg" />
|
9
|
-
</div>
|
10
|
-
|
11
|
-
<div id="page" class="row">
|
12
|
-
<div id="div-main" class="small-12 large-7 columns">
|
13
|
-
<div class="show-for-medium-down" style="padding: 10px;"><%= dc_render(:responsive, method: 'i_move') %></div>
|
14
|
-
[main]
|
15
|
-
</div>
|
16
|
-
<div id="div-right" class="small-12 large-5 columns">
|
17
|
-
<div class="show-for-medium-up"><%= dc_render(:responsive, method: 'i_move') %></div>
|
18
|
-
<%= dc_render(:responsive, method: 'roller') %>
|
19
|
-
<div class="na-mailing"><%= dc_render(:dc_poll, poll_id: 'mail-subscribe') %></div>
|
20
|
-
<div class="na-mailing"><%= dc_render(:sport, method: 'send_mail') %></div>
|
21
|
-
</div>
|
22
|
-
</div>
|
23
|
-
|
24
|
-
<div id="site-footer">
|
25
|
-
<%= dc_render(:dc_piece, id: 'site-footer') %>
|
26
|
-
</div>
|
27
|
-
|
28
|
-
</div>
|
29
|
-
<%= dc_render(:responsive, method: 'eu_cookies') %>
|
30
|
-
<%= dc_render(:dc_common, method: 'google_analytics') %>
|
31
|
-
|
32
|
-
<!-- dc_design.body field data -->
|
33
|
-
<% main="\<\%= dc_render(:sport, method: 'seznam') \%\>" %>
|
34
|
-
|
35
|
-
<%= dc_replace_in_design(replace: '[main]', with: main) %>
|
@@ -1,32 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c) 2012+ Damjan Rems
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
23
|
-
|
24
|
-
class Mailing
|
25
|
-
include Mongoid::Document
|
26
|
-
include Mongoid::Timestamps
|
27
|
-
|
28
|
-
field :email, type: String, default: ''
|
29
|
-
field :active, type: Boolean, default: true
|
30
|
-
|
31
|
-
validates :email, presence: true
|
32
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/* This will center and automatically resize top picture. Picture size is 1280x480px */
|
2
|
-
.site-top {
|
3
|
-
text-align: center;
|
4
|
-
position: relative;
|
5
|
-
height: 0;
|
6
|
-
overflow: hidden;
|
7
|
-
}
|
8
|
-
.picture-top { padding-bottom:37.5%; }
|
9
|
-
|
10
|
-
/* Prevent too much padding when resized past 1400 px */
|
11
|
-
@media screen and (min-width: 1400px) {
|
12
|
-
.picture-top { padding-bottom:28%; }
|
13
|
-
}
|
14
|
-
|
15
|
-
#page {max-width: 820px; margin: 0 auto;}
|
16
|
-
|
17
|
-
#site-footer {
|
18
|
-
color: white;
|
19
|
-
background: linear-gradient(#474748 4%, #191a1a 100%);
|
20
|
-
}
|
21
|
-
#site-footer div { max-width: 820px; margin: 0 auto;}
|
22
|
-
#site-footer a {color: #fff; font-weight: normal;}
|
23
|
-
#site-footer a:hover {color: #222;}
|
24
|
-
|
25
|
-
@media screen and (max-width: 640px) {
|
26
|
-
html { font-size: 18px; }
|
27
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
#--
|
3
|
-
# Copyright (c) 2012-2013 Damjan Rems
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
#++
|
24
|
-
class ResponsiveController < DcApplicationController
|
25
|
-
protect_from_forgery
|
26
|
-
|
27
|
-
####################################################################
|
28
|
-
# Checks if email is OK.
|
29
|
-
####################################################################
|
30
|
-
def email_ok(email)
|
31
|
-
email = email.downcase.strip
|
32
|
-
return 'e-mail is empty!' unless email.size > 0
|
33
|
-
return 'e-mail is not validd!' unless email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
|
34
|
-
''
|
35
|
-
end
|
36
|
-
|
37
|
-
####################################################################
|
38
|
-
# This action is called when submit is selected on subscribe poll form.
|
39
|
-
####################################################################
|
40
|
-
def subscribe
|
41
|
-
check = emyil_ok(params[:record][:email])
|
42
|
-
if check.size > 0
|
43
|
-
flash[:error] = check
|
44
|
-
else
|
45
|
-
email = params[:record][:email].strip.downcase
|
46
|
-
if Mailing.find_by(email: email)
|
47
|
-
flash[:error] = 'e-mail already exists!'
|
48
|
-
else
|
49
|
-
Mailing.create(email: email)
|
50
|
-
flash[:info] = 'e-mail recorded. Thank you for your interest.'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
redirect_to params[:return_to]
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
#--
|
3
|
-
# Copyright (c) 2014+ Damjan Rems
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
# a copy of this software and associated documentation files (the
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
# the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be
|
14
|
-
# included in all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
#++
|
24
|
-
|
25
|
-
########################################################################
|
26
|
-
#
|
27
|
-
########################################################################
|
28
|
-
class ResponsiveRenderer < DcRenderer
|
29
|
-
|
30
|
-
########################################################################
|
31
|
-
# i_move may move between right and main part.
|
32
|
-
########################################################################
|
33
|
-
def i_move
|
34
|
-
html = '<div id="i-move"><h2>I MOVE WHEN ON PHONE<h2>'
|
35
|
-
html << 'Contents'
|
36
|
-
html << '</div>'
|
37
|
-
end
|
38
|
-
|
39
|
-
########################################################################
|
40
|
-
# Roller rolls ads in it's div. With little help of slick javascript library.
|
41
|
-
########################################################################
|
42
|
-
def roller
|
43
|
-
html = '<div class="sponsors">'
|
44
|
-
# Ads are saved in home page parts which have 'ads' written in div_id field.
|
45
|
-
home = DcPage.find_by(dc_site_id: @parent.dc_get_site._id, subject_link: 'home')
|
46
|
-
ads = home.dc_parts.where(div_id: 'ads')
|
47
|
-
ads = ads.and(active: true) unless @parent.dc_edit_mode? # active only
|
48
|
-
ads = ads.order_by(order: 1).to_a
|
49
|
-
html << 'OUR SPONSORS' if ads.size > 0 or @parent.dc_edit_mode?
|
50
|
-
ads.each do |ad|
|
51
|
-
# Edit link for ad
|
52
|
-
if @parent.dc_edit_mode?
|
53
|
-
opts = { controller: 'cmsedit', action: 'edit', formname: 'ad',
|
54
|
-
table: "#{@parent.site.page_table};dc_part", ids: home._id,
|
55
|
-
id: ad._id, title: 'Edit sponsor\'s ad.' }
|
56
|
-
html << @parent.dc_link_for_edit(opts)
|
57
|
-
end
|
58
|
-
html << "<div>#{@parent.link_to(@parent.image_tag(ad.picture),ad.link, target: '_blank')}</div>"
|
59
|
-
end
|
60
|
-
# Link for new ad
|
61
|
-
if @parent.dc_edit_mode?
|
62
|
-
opts = { controller: 'cmsedit', action: 'create', formname: 'ad',
|
63
|
-
table: "#{@parent.site.page_table};dc_part", ids: home._id,
|
64
|
-
'dc_part.div_id' => 'ads', title: 'Add new sponsor\'s ad!' }
|
65
|
-
html << @parent.dc_link_for_create(opts)
|
66
|
-
end
|
67
|
-
html << '</div>'
|
68
|
-
html << @parent.javascript_tag( "$('.sponsors').slick({
|
69
|
-
autoplay: true, infinite: true, autoplaySpeed: 2000, speed: 2000,
|
70
|
-
arrows: false});" ) unless @parent.dc_edit_mode?
|
71
|
-
html
|
72
|
-
end
|
73
|
-
|
74
|
-
########################################################################
|
75
|
-
# EU cookies message.
|
76
|
-
########################################################################
|
77
|
-
def eu_cookies
|
78
|
-
html =<<EOT
|
79
|
-
<div id="cookies-msg">
|
80
|
-
Our web site is using cookies in order to ensure best user experience.
|
81
|
-
By visiting our web site you agree to our conditions.
|
82
|
-
<span class="cookies-yes">Close</span>
|
83
|
-
#{@parent.link_to('More information about cookies!','/cookies')}
|
84
|
-
</div>
|
85
|
-
EOT
|
86
|
-
html.html_safe
|
87
|
-
end
|
88
|
-
|
89
|
-
########################################################################
|
90
|
-
# Send mail dialog. Data can also be rendered by Rails render method.
|
91
|
-
########################################################################
|
92
|
-
def send_mail
|
93
|
-
@parent.render(partial: 'responsive_views/send_email')
|
94
|
-
end
|
95
|
-
|
96
|
-
########################################################################
|
97
|
-
#
|
98
|
-
########################################################################
|
99
|
-
def render_html
|
100
|
-
method = @opts[:method] || 'default'
|
101
|
-
respond_to?(method) ? send(method) : "#{self.class}. Method #{method} not found!"
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
## YAML Template.
|
2
|
-
dc_poll:
|
3
|
-
name: login
|
4
|
-
display: td
|
5
|
-
operation: link
|
6
|
-
parameters: '/dc_common/process_login'
|
7
|
-
title: Autocreated login form
|
8
|
-
|
9
|
-
dc_poll_items:
|
10
|
-
1:
|
11
|
-
type: text_field
|
12
|
-
name: username
|
13
|
-
size: 15
|
14
|
-
text: Username
|
15
|
-
|
16
|
-
2:
|
17
|
-
type: password_field
|
18
|
-
name: password
|
19
|
-
size: 15
|
20
|
-
text: Password
|
21
|
-
|
22
|
-
3:
|
23
|
-
type: submit_tag
|
24
|
-
name: send
|
25
|
-
text: Login
|
26
|
-
|
data/lib/tasks/send_mail.rake
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
require 'net/smtp'
|
3
|
-
Rake.application.options.trace = true
|
4
|
-
|
5
|
-
##############################################################################
|
6
|
-
# Add style to message body.
|
7
|
-
##############################################################################
|
8
|
-
def get_body(doc)
|
9
|
-
style =<<EOT
|
10
|
-
<style>
|
11
|
-
body {font-family: sans-serif;font-size:12px;}
|
12
|
-
</style>
|
13
|
-
EOT
|
14
|
-
"#{style}#{doc.body}"
|
15
|
-
end
|
16
|
-
|
17
|
-
###########################################################################
|
18
|
-
# Actually sends mail to mail server
|
19
|
-
###########################################################################
|
20
|
-
def smtp_send(mail)
|
21
|
-
smtp = Net::SMTP.start( ActionMailer::Base.smtp_settings[:address] )
|
22
|
-
begin
|
23
|
-
smtp.send_message mail.to_s, 'pmaster@ozs.si', mail.to
|
24
|
-
$mail_sent << mail.to
|
25
|
-
rescue Exception => exc
|
26
|
-
p "#{mail.to} : #{exc.message}"
|
27
|
-
$mail_errors << "#{mail.to} : #{exc.message}\n"
|
28
|
-
ensure
|
29
|
-
smtp.finish
|
30
|
-
end
|
31
|
-
sleep 0.4
|
32
|
-
end
|
33
|
-
=begin
|
34
|
-
##############################################################################
|
35
|
-
# Include pictures as inline attachments and update coresponding links in the message.
|
36
|
-
##############################################################################
|
37
|
-
def update_attachments(doc)
|
38
|
-
offset = 0
|
39
|
-
# find img tags
|
40
|
-
while i1 = doc.body.index('<img', offset)
|
41
|
-
i2 = doc.body.index('/>', i1) + 1
|
42
|
-
# find src tag
|
43
|
-
s1 = doc.body.index('src="', i1) + 6
|
44
|
-
s2 = doc.body.index('"', s1) - 1
|
45
|
-
filename = doc.body[s1..s2]
|
46
|
-
cid = File.basename(filename)
|
47
|
-
# read file into inline attachments and replace link with new link
|
48
|
-
attachments.inline[cid] = File.read( Rails.root.join('public', filename) )
|
49
|
-
doc.body[(s1-1)..s2] = "cid:#{cid}"
|
50
|
-
#
|
51
|
-
offset = i1 + 10 # just in case ..
|
52
|
-
# replace style with pure html height= and width= because inline style doesn't work in mailers. At least not in outlook.
|
53
|
-
s1 = doc.body.index('style="', i1) + 7
|
54
|
-
next if s1.nil? or s1 > i2 # style might not be present
|
55
|
-
s2 = doc.body.index('"', s1) - 1
|
56
|
-
style = doc.body[s1..s2]
|
57
|
-
h_w = ''
|
58
|
-
style.split(';').each do |hw|
|
59
|
-
a = hw.split(':')
|
60
|
-
h_w << "#{a.first}='#{a.last.strip.gsub('px','')}' "
|
61
|
-
end
|
62
|
-
doc.body[(s1-7)..s2] = h_w
|
63
|
-
end
|
64
|
-
end
|
65
|
-
=end
|
66
|
-
##############################################################################
|
67
|
-
# Include pictures as inline attachments and update coresponding links in the message.
|
68
|
-
##############################################################################
|
69
|
-
def update_attachments(docbody, mail)
|
70
|
-
offset, n = 0, 0
|
71
|
-
# find img tags
|
72
|
-
while i1 = docbody.index('<img', offset)
|
73
|
-
i2 = docbody.index('/>', i1) + 1
|
74
|
-
# find src tag
|
75
|
-
s1 = docbody.index('src="', i1) + 6
|
76
|
-
s2 = docbody.index('"', s1) - 1
|
77
|
-
filename = docbody[s1..s2]
|
78
|
-
cid = File.basename(filename)
|
79
|
-
# read file into inline attachments and replace link with new link
|
80
|
-
mail.attachments[cid] = File.read( Rails.root.join('public', filename) )
|
81
|
-
mail.parts[n].content_id = cid
|
82
|
-
mail.parts[n].content_disposition = "inline; filename=#{cid}"
|
83
|
-
|
84
|
-
# attachments.inline[cid] = File.read( Rails.root.join('public', filename) )
|
85
|
-
docbody[(s1-1)..s2] = "cid:#{cid}"
|
86
|
-
n += 1
|
87
|
-
#
|
88
|
-
offset = i1 + 10 # just in case ..
|
89
|
-
# replace style with pure html height= and width= because inline style doesn't work in mailers. At least not in outlook.
|
90
|
-
s1 = docbody.index('style="', i1) + 7
|
91
|
-
next if s1.nil? or s1 > i2 # style might not be present
|
92
|
-
s2 = docbody.index('"', s1) - 1
|
93
|
-
style = docbody[s1..s2]
|
94
|
-
h_w = ''
|
95
|
-
style.split(';').each do |hw|
|
96
|
-
a = hw.split(':')
|
97
|
-
h_w << "#{a.first}='#{a.last.strip.gsub('px','')}' "
|
98
|
-
end
|
99
|
-
docbody[(s1-7)..s2] = h_w
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
##############################################################################
|
104
|
-
# Send document to test e-mail address
|
105
|
-
##############################################################################
|
106
|
-
def send_test(doc)
|
107
|
-
mail = Mail.new
|
108
|
-
mail.to = doc.to_test
|
109
|
-
mail.subject = doc.subject
|
110
|
-
mail.from = doc.from
|
111
|
-
update_attachments(doc, mail)
|
112
|
-
#
|
113
|
-
body = (doc.css.to_s.size > 5 ? "<style type=\"text/css\">#{doc.css}</style>" : '') + doc.body
|
114
|
-
html = Mail::Part.new do
|
115
|
-
content_type 'text/html; charset=UTF8'
|
116
|
-
body body
|
117
|
-
end
|
118
|
-
mail.html_part = html
|
119
|
-
smtp_send(mail)
|
120
|
-
end
|
121
|
-
|
122
|
-
##############################################################################
|
123
|
-
# Returns array of addresses mail will be send to.
|
124
|
-
##############################################################################
|
125
|
-
def get_adresses(doc)
|
126
|
-
a = []
|
127
|
-
# direct specified addresses
|
128
|
-
if doc.to_address.size > 5
|
129
|
-
doc.to_address.split("\n").each do |line|
|
130
|
-
doc.to_address.split(/,|;| /).each { |address| a << [address.strip.downcase] }
|
131
|
-
end
|
132
|
-
end
|
133
|
-
# maling lists
|
134
|
-
doc.to_list.each do |id|
|
135
|
-
list = DcMailList.find(id)
|
136
|
-
DcMailAddress.where('dc_mail_list_members.dc_mail_list_id' => id, active: true).each do |addr|
|
137
|
-
address = ''
|
138
|
-
if addr.email.to_s.size > 5
|
139
|
-
address = addr.email
|
140
|
-
elsif addr.dc_user_id
|
141
|
-
address = DcUser.find(addr.dc_user_id).email.to_s
|
142
|
-
end
|
143
|
-
a << [address.strip.downcase, addr.id] if address.size > 1
|
144
|
-
end
|
145
|
-
end
|
146
|
-
# return only unique addresses
|
147
|
-
a.uniq { |s| s.first }
|
148
|
-
end
|
149
|
-
|
150
|
-
##############################################################################
|
151
|
-
# Send document to defined recipients
|
152
|
-
##############################################################################
|
153
|
-
def sending(doc)
|
154
|
-
addresses = get_adresses(doc)
|
155
|
-
|
156
|
-
# Write list of all addresses to file. Very useful when something gets wrong
|
157
|
-
File.open(Rails.root.join('log/sendmail.list'),'w') {|f| f.write(addresses.join("\n")) }
|
158
|
-
addresses.each do |a|
|
159
|
-
mail = Mail.new
|
160
|
-
mail.subject = doc.subject
|
161
|
-
mail.from = doc.from
|
162
|
-
docbody = doc.body.dup
|
163
|
-
update_attachments(docbody, mail)
|
164
|
-
url = "<a href=\"http://#{doc.dc_site.name}/dc_mail/unsubscribe?id_list=#{a.last}\">#{I18n.t('drgcms.dc_mail.unsubscription')}</a>"
|
165
|
-
#
|
166
|
-
body = (doc.css.to_s.size > 5 ? "<style type=\"text/css\">#{doc.css}</style>" : '')
|
167
|
-
body << docbody.sub('%{unsubscription}', url)
|
168
|
-
part = Mail::Part.new do
|
169
|
-
content_type 'text/html; charset=UTF8'
|
170
|
-
body body
|
171
|
-
end
|
172
|
-
mail.html_part = part
|
173
|
-
mail.to = a.first
|
174
|
-
smtp_send(mail)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
##############################################################################
|
179
|
-
# Send document to test e-mail address
|
180
|
-
##############################################################################
|
181
|
-
def send_report(doc, text, status = :ok)
|
182
|
-
mail = Mail.new
|
183
|
-
mail.to = doc.from
|
184
|
-
mail.subject = "#{(status == :ok ? '' : I18n.t('drgcms.error'))}#{I18n.t('drgcms.dc_mail.report')}: #{doc.subject}"
|
185
|
-
mail.from = 'SENDMAIL REPORT'
|
186
|
-
html = Mail::Part.new do
|
187
|
-
content_type 'text/html; charset=UTF8'
|
188
|
-
body text.gsub("\n",'<br>')
|
189
|
-
end
|
190
|
-
smtp_send(mail)
|
191
|
-
end
|
192
|
-
|
193
|
-
namespace :drg_cms do
|
194
|
-
namespace :sendmail do
|
195
|
-
###########################################################################
|
196
|
-
# sendmail:test
|
197
|
-
###########################################################################
|
198
|
-
desc 'Sends mail to test recipient!'
|
199
|
-
|
200
|
-
task :test => :environment do
|
201
|
-
begin
|
202
|
-
id = ENV["MAIL_ID"] || '517a7eb27246cd2958000104'
|
203
|
-
doc = DcMail.find(id)
|
204
|
-
send_test(doc)
|
205
|
-
rescue Exception => exc
|
206
|
-
stack = "\n#{Time.now.strftime('%d.%m.%Y %H:%M')}:#{exc.to_s} + \n"
|
207
|
-
exc.backtrace.each {|c| stack << "#{c}\n" }
|
208
|
-
p stack.to_yaml
|
209
|
-
File.open(Rails.root.join('log/error.log'),'a+') {|f| f.write(stack) }
|
210
|
-
send_report(doc)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
###########################################################################
|
215
|
-
# sendmail:send
|
216
|
-
###########################################################################
|
217
|
-
desc 'Sends mail to all recipients!'
|
218
|
-
|
219
|
-
task :sending => :environment do
|
220
|
-
$mail_errors, $mail_sent = [], []
|
221
|
-
ok = false
|
222
|
-
begin
|
223
|
-
id = ENV["MAIL_ID"] || '517a7eb27246cd2958000104'
|
224
|
-
doc = DcMail.find(id)
|
225
|
-
if doc.status == 1 # status must be ready
|
226
|
-
doc.status = 2; doc.save
|
227
|
-
sending(doc)
|
228
|
-
else
|
229
|
-
send_report(doc, I18n.t('drgcms.dc_mail.message_status_error'), :error )
|
230
|
-
end
|
231
|
-
ok = true
|
232
|
-
rescue Exception => exc
|
233
|
-
stack = "ERROR! rake drgcms:sendmail:send\n\n#{Time.now.strftime('%d.%m.%Y %H:%M')}:#{exc.to_s} \n"
|
234
|
-
exc.backtrace.each {|c| stack << "#{c}\n\n" }
|
235
|
-
stack << "Last OK mail sent:#{$mail_sent.last}\n"
|
236
|
-
p stack.to_yaml
|
237
|
-
File.open(Rails.root.join('log/error.log'),'a+') {|f| f.write(stack) }
|
238
|
-
send_report(doc, stack, :error )
|
239
|
-
doc.status = 3; doc.save
|
240
|
-
end
|
241
|
-
# Send report if OK
|
242
|
-
if ok
|
243
|
-
msg = I18n.t('drgcms.dc_mail.message_sent_to', :number => $mail_sent.size) + "\n\n"
|
244
|
-
msg << I18n.t('drgcms.dc_mail.message_errors', :number => $mail_errors.size) + "\n"
|
245
|
-
msg << $mail_errors.join("\n")
|
246
|
-
doc.status = 10; doc.save
|
247
|
-
send_report(doc, msg)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|