infopark_cloud_connector 6.8.3.73.75172665 → 6.8.3.115.227021242

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ module RailsConnector
3
3
  class ObjsController < ActionController::Base
4
4
 
5
5
  before_filter :restrict_non_allow_access
6
+ before_filter :load_object
6
7
 
7
8
  respond_to :json
8
9
 
@@ -10,6 +11,15 @@ module RailsConnector
10
11
  raise "Required parameter 'obj' is missing." unless params[:obj].present?
11
12
  raise "Parameter 'obj' is not a hash." unless params[:obj].is_a?(Hash)
12
13
 
14
+ convert_html_keys = params[:obj].keys.select do |key|
15
+ @obj.type_of_attribute(key.to_s) == 'html'
16
+ end
17
+
18
+ convert_html_keys.each do |key|
19
+ params[:obj][key] = ContentConversion.convert_html_links(
20
+ params[:obj][key], request.host, request.port)
21
+ end
22
+
13
23
  begin
14
24
  changed_obj = CmsRestApi.put(
15
25
  "revisions/#{Workspace.current.revision_id}/objs/#{params[:id]}",
@@ -23,6 +33,10 @@ module RailsConnector
23
33
 
24
34
  private
25
35
 
36
+ def load_object
37
+ @obj = Obj.find(params[:id])
38
+ end
39
+
26
40
  def restrict_non_allow_access
27
41
  unless allow_access?
28
42
  render(:text => 'Forbidden', :status => 403)
@@ -3,7 +3,7 @@ module RailsConnector
3
3
  module CmsTagHelper
4
4
 
5
5
  # A wrapper for [http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag]
6
- # If {cms_editor_mode?} returns true, it also renders additional data attributes, which are needed for inline editing.
6
+ # If {cms_editor_mode?} returns true, it also renders additional data attributes, which are needed for inplace editing.
7
7
  # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
8
8
  # @param obj [Obj] A {Obj} from which attribute is read.
9
9
  # @param attribute [String, Symbol] Which attribute should be render.
@@ -14,6 +14,8 @@ module RailsConnector
14
14
  'data-ip-field-obj-class' => obj.obj_class,
15
15
  'data-ip-field-name' => attribute,
16
16
  'data-ip-field-type' => obj.type_of_attribute(attribute.to_s),
17
+ # Concate with empty string to disable html_safe:
18
+ 'data-ip-field-original-content' => "" + display_original_value(obj[attribute]),
17
19
  }) if cms_editor_mode?
18
20
 
19
21
  content_tag(tag_name, display_value(obj[attribute]), options)
@@ -3,13 +3,13 @@ module RailsConnector
3
3
  module EditingHelper
4
4
 
5
5
  def include_editing_stylesheet
6
- if inline_editing_allowed?
6
+ if inplace_editing_allowed?
7
7
  stylesheet_link_tag :infopark_editing
8
8
  end
9
9
  end
10
10
 
11
11
  def include_editing_javascript
12
- if inline_editing_allowed?
12
+ if inplace_editing_allowed?
13
13
  raw <<-EOF
14
14
  #{javascript_include_tag(:infopark_editing)}
15
15
  #{javascript_tag('$(function() { infopark.editing.initialize(); });')}
@@ -17,7 +17,7 @@ module RailsConnector
17
17
  end
18
18
  end
19
19
 
20
- def inline_editing_allowed?
20
+ def inplace_editing_allowed?
21
21
  Configuration.editing_auth_callback.call(request.env)
22
22
  end
23
23
 
@@ -4307,44 +4307,47 @@ eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a
4307
4307
  var infopark = (function(that) {
4308
4308
  var editing_active = false;
4309
4309
 
4310
- var save_obj_attribute = function(obj_id, attribute_name, content, success, error) {
4310
+ var save_obj_attribute = function(obj_id, attribute_name, content) {
4311
4311
  var url = window.location.protocol+"//"+window.location.host + "/__ipcms/objs/" + obj_id;
4312
4312
  var elements = {};
4313
4313
  elements[attribute_name] = content;
4314
4314
 
4315
- jQuery.ajax(url, {
4315
+ return jQuery.ajax(url, {
4316
4316
  type: 'PUT',
4317
4317
  dataType: 'json',
4318
4318
  contentType: 'application/json; charset=utf-8',
4319
4319
  data: JSON.stringify({
4320
4320
  obj: elements
4321
- }),
4322
- success: function(data, textStatus, jqXHR) {
4323
- success();
4324
- },
4325
- error: function(jqXHR, textStatus, errorThrown) {
4326
- error(textStatus);
4327
- }
4321
+ })
4322
+ }).then(function(data, textStatus, jqXHR) {
4323
+ return;
4324
+ }, function(jqXHR, textStatus, errorThrown) {
4325
+ return textStatus;
4328
4326
  });
4329
4327
  };
4330
4328
 
4331
4329
  var save_action = function(obj, event, key) {
4332
4330
  var obj_id = obj.$content.data('ip-field-id');
4333
4331
  var attribute_name = obj.$content.data('ip-field-name');
4334
- var new_content = $.trim(obj.$editor.text());
4332
+ var new_content;
4333
+ if(obj.$content.data('ip-field-type') === 'string') {
4334
+ new_content = obj.$editor.text();
4335
+ } else {
4336
+ new_content = obj.getCode();
4337
+ }
4338
+ new_content = $.trim(new_content);
4335
4339
 
4336
4340
  obj.$box.addClass('ip_field_saving');
4337
4341
 
4338
- var success = function() {
4342
+ save_obj_attribute(
4343
+ obj_id, attribute_name, new_content
4344
+ ).done(function() {
4339
4345
  obj.$editor.destroyEditor();
4340
- obj.$content.removeData('ip-field-original-content');
4341
- };
4342
- var error = function(error_message) {
4346
+ obj.$content.data('ip-field-original-content', new_content);
4347
+ }).fail(function(error_message) {
4343
4348
  obj.$box.removeClass('ip_field_saving');
4344
4349
  infopark.alert(error_message);
4345
- };
4346
-
4347
- save_obj_attribute(obj_id, attribute_name, new_content, success, error);
4350
+ });
4348
4351
  };
4349
4352
 
4350
4353
  var cancel_action = function(obj, event, key) {
@@ -4381,6 +4384,20 @@ var infopark = (function(that) {
4381
4384
  };
4382
4385
  break;
4383
4386
 
4387
+ case 'html':
4388
+ special_options = {
4389
+ buttons: ['saveButton', 'cancelButton',
4390
+ '|', 'formatting',
4391
+ '|', 'bold', 'italic', 'deleted', 'underline',
4392
+ '|', 'unorderedlist', 'orderedlist',
4393
+ '|', 'table', 'link',
4394
+ '|', 'fontcolor', 'backcolor',
4395
+ '|', 'horizontalrule',
4396
+ '|', 'html'
4397
+ ]
4398
+ };
4399
+ break;
4400
+
4384
4401
  default:
4385
4402
  return null;
4386
4403
  }
@@ -4413,7 +4430,7 @@ var infopark = (function(that) {
4413
4430
  $(dom_item).on('click.ip-editing', function(e) {
4414
4431
  e.preventDefault();
4415
4432
 
4416
- $(dom_item).data('ip-field-original-content', $(dom_item).html());
4433
+ $(dom_item).html($(dom_item).data('ip-field-original-content'));
4417
4434
  $(dom_item).redactor(redactor_options);
4418
4435
  });
4419
4436
  }
@@ -1,5 +1,9 @@
1
1
  module ::RailsConnector
2
2
  class CloudEngine < Rails::Engine
3
+ initializer "cloud_connector.add_assets" do |app|
4
+ # Specify which file should be precompiled for packaging
5
+ app.config.assets.precompile += %w( infopark_editing.js infopark_editing.css )
6
+ end
3
7
  end
4
8
  end
5
9
 
@@ -0,0 +1,89 @@
1
+ require 'nokogiri'
2
+ require 'addressable/uri'
3
+
4
+ module RailsConnector
5
+
6
+ class ContentConversion
7
+ def self.convert_html_links(input, request_host, request_port)
8
+ doc = Nokogiri::HTML.parse("<div class='internal_jump_point'>#{input}</div>")
9
+
10
+ doc.css('body a').each do |a_tag|
11
+ item = a_tag.attributes['href']
12
+ item.value = convert_link(item.value, request_host, request_port)
13
+ end
14
+
15
+ doc.css('body img').each do |img_tag|
16
+ item = img_tag.attributes['src']
17
+ item.value = convert_link(item.value, request_host, request_port)
18
+ end
19
+
20
+ new_html = doc.css('body div.internal_jump_point').inner_html
21
+
22
+ nbsp = Nokogiri::HTML("&nbsp;").text
23
+ new_html.gsub(nbsp, "&nbsp;")
24
+ end
25
+
26
+ private
27
+
28
+ def self.convert_link(target, request_host, request_port)
29
+ if target.present?
30
+ uri = Addressable::URI.parse(target)
31
+
32
+ if uri.absolute?
33
+ if internal_url?(uri, request_host, request_port)
34
+ target = convert_single_link(uri)
35
+ end
36
+ else
37
+ if uri.path.present?
38
+ target = convert_single_link(uri)
39
+ end
40
+ end
41
+ end
42
+
43
+ target
44
+ end
45
+
46
+ def self.internal_url?(uri, request_host, request_port)
47
+ if request_host == uri.host
48
+ if uri.port.present?
49
+ uri.port == Integer(request_port)
50
+ else
51
+ true
52
+ end
53
+ else
54
+ false
55
+ end
56
+ end
57
+
58
+ def self.convert_single_link(uri)
59
+ uri.path = '/' unless uri.path.present?
60
+ uri.port = nil
61
+ uri.host = nil
62
+ uri.scheme = nil
63
+
64
+ if obj_id = determine_obj_id(uri.to_s)
65
+ uri.scheme = 'objid'
66
+ uri.path = obj_id
67
+ else
68
+ uri.scheme = 'external'
69
+ end
70
+
71
+ uri.to_s
72
+ end
73
+
74
+ def self.determine_obj_id(target)
75
+ route = Rails.application.routes.recognize_path(target, :method => :get)
76
+ if route[:controller] == 'rails_connector/cms_dispatch'
77
+ begin
78
+ if id = route[:id]
79
+ Obj.find(id).id
80
+ elsif permalink = route[:permalink]
81
+ CmsEnv.find_permalink_by_param(permalink).id
82
+ end
83
+ rescue RailsConnector::ResourceNotFound
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.8.3.73.75172665
4
+ version: 6.8.3.115.227021242
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -43,6 +43,38 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '1.6'
46
+ - !ruby/object:Gem::Dependency
47
+ name: nokogiri
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.6
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.6
62
+ - !ruby/object:Gem::Dependency
63
+ name: addressable
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.3.2
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.2
46
78
  - !ruby/object:Gem::Dependency
47
79
  name: kvom
48
80
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +82,7 @@ dependencies:
50
82
  requirements:
51
83
  - - '='
52
84
  - !ruby/object:Gem::Version
53
- version: 6.8.3.73.75172665
85
+ version: 6.8.3.115.227021242
54
86
  type: :runtime
55
87
  prerelease: false
56
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +90,7 @@ dependencies:
58
90
  requirements:
59
91
  - - '='
60
92
  - !ruby/object:Gem::Version
61
- version: 6.8.3.73.75172665
93
+ version: 6.8.3.115.227021242
62
94
  description: The Cloud Connector for Infopark CMS Fiona enables you to develop modern,
63
95
  dynamic Web 2.0 applications using Ruby on Rails and at the same time display CMS
64
96
  managed content.
@@ -98,6 +130,7 @@ files:
98
130
  - lib/rails_connector/cms_cache_storage.rb
99
131
  - lib/rails_connector/cms_rest_api.rb
100
132
  - lib/rails_connector/content_cache.rb
133
+ - lib/rails_connector/content_conversion.rb
101
134
  - lib/rails_connector/content_service.rb
102
135
  - lib/rails_connector/content_state.rb
103
136
  - lib/rails_connector/content_state_caching.rb
@@ -152,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
185
  version: '0'
153
186
  segments:
154
187
  - 0
155
- hash: -859921965
188
+ hash: 723525395
156
189
  required_rubygems_version: !ruby/object:Gem::Requirement
157
190
  none: false
158
191
  requirements: