Commit 3bdce46182d68be9fb2663b4d692ebed38120b9c
1 parent
c2223bbc
Exists in
master
and in
18 other branches
piwik: allow custom path for url
Showing
6 changed files
with
29 additions
and
7 deletions
Show diff stats
plugins/piwik/lib/ext/environment.rb
@@ -2,6 +2,7 @@ require_dependency 'environment' | @@ -2,6 +2,7 @@ require_dependency 'environment' | ||
2 | 2 | ||
3 | class Environment | 3 | class Environment |
4 | settings_items :piwik_domain | 4 | settings_items :piwik_domain |
5 | + settings_items :piwik_path, :default => 'piwik' | ||
5 | settings_items :piwik_site_id | 6 | settings_items :piwik_site_id |
6 | - attr_accessible :piwik_domain, :piwik_site_id | 7 | + attr_accessible :piwik_domain, :piwik_site_id, :piwik_path |
7 | end | 8 | end |
plugins/piwik/lib/piwik_plugin.rb
@@ -17,7 +17,9 @@ class PiwikPlugin < Noosfero::Plugin | @@ -17,7 +17,9 @@ class PiwikPlugin < Noosfero::Plugin | ||
17 | domain = context.environment.piwik_domain | 17 | domain = context.environment.piwik_domain |
18 | site_id = context.environment.piwik_site_id | 18 | site_id = context.environment.piwik_site_id |
19 | unless domain.blank? || site_id.blank? | 19 | unless domain.blank? || site_id.blank? |
20 | - expanded_template('tracking-code.rhtml',{:domain => domain, :site_id => site_id}) | 20 | + piwik_url = "#{domain}/#{context.environment.piwik_path}" |
21 | + piwik_url = "#{piwik_url}/" unless piwik_url.end_with?('/') | ||
22 | + expanded_template('tracking-code.rhtml', {:site_id => site_id, :piwik_url => piwik_url}) | ||
21 | end | 23 | end |
22 | end | 24 | end |
23 | 25 |
plugins/piwik/test/functional/piwik_plugin_test.rb
@@ -19,10 +19,12 @@ class PiwikPluginAdminControllerTest < ActionController::TestCase | @@ -19,10 +19,12 @@ class PiwikPluginAdminControllerTest < ActionController::TestCase | ||
19 | 19 | ||
20 | should 'update piwik plugin settings' do | 20 | should 'update piwik plugin settings' do |
21 | assert_nil @environment.reload.piwik_domain | 21 | assert_nil @environment.reload.piwik_domain |
22 | + assert_equal 'piwik', @environment.reload.piwik_path | ||
22 | assert_nil @environment.reload.piwik_site_id | 23 | assert_nil @environment.reload.piwik_site_id |
23 | - post :index, :environment => { :piwik_domain => 'http://something', :piwik_site_id => 10 } | ||
24 | - assert_not_nil @environment.reload.piwik_domain | ||
25 | - assert_not_nil @environment.reload.piwik_site_id | 24 | + post :index, :environment => { :piwik_domain => 'something', :piwik_site_id => 10, :piwik_path => 'some_path' } |
25 | + assert_equal 'something', @environment.reload.piwik_domain | ||
26 | + assert_equal '10', @environment.reload.piwik_site_id | ||
27 | + assert_equal 'some_path', @environment.reload.piwik_path | ||
26 | end | 28 | end |
27 | 29 | ||
28 | end | 30 | end |
plugins/piwik/test/unit/piwik_plugin_test.rb
@@ -39,4 +39,19 @@ class PiwikPluginTest < ActiveSupport::TestCase | @@ -39,4 +39,19 @@ class PiwikPluginTest < ActiveSupport::TestCase | ||
39 | assert_respond_to Environment.new, :piwik_site_id | 39 | assert_respond_to Environment.new, :piwik_site_id |
40 | end | 40 | end |
41 | 41 | ||
42 | + should 'set default path to piwik' do | ||
43 | + @environment.piwik_domain = 'piwik.domain.example.com' | ||
44 | + @environment.piwik_site_id = 5 | ||
45 | + @plugin.expects(:expanded_template).with('tracking-code.rhtml', {:site_id => @environment.piwik_site_id, :piwik_url => "piwik.domain.example.com/piwik/"}) | ||
46 | + @plugin.body_ending | ||
47 | + end | ||
48 | + | ||
49 | + should 'allow empty path in piwik url' do | ||
50 | + @environment.piwik_domain = 'piwik.domain.example.com' | ||
51 | + @environment.piwik_path = '' | ||
52 | + @environment.piwik_site_id = 5 | ||
53 | + @plugin.expects(:expanded_template).with('tracking-code.rhtml', {:site_id => @environment.piwik_site_id, :piwik_url => "piwik.domain.example.com/"}) | ||
54 | + @plugin.body_ending | ||
55 | + end | ||
56 | + | ||
42 | end | 57 | end |
plugins/piwik/views/piwik_plugin_admin/index.html.erb
@@ -4,6 +4,8 @@ | @@ -4,6 +4,8 @@ | ||
4 | 4 | ||
5 | <%= labelled_form_field _('Piwik domain'), f.text_field(:piwik_domain) %> | 5 | <%= labelled_form_field _('Piwik domain'), f.text_field(:piwik_domain) %> |
6 | 6 | ||
7 | + <%= labelled_form_field _('Piwik path'), f.text_field(:piwik_path) %> | ||
8 | + | ||
7 | <%= labelled_form_field _('Piwik site id'), f.text_field(:piwik_site_id) %> | 9 | <%= labelled_form_field _('Piwik site id'), f.text_field(:piwik_site_id) %> |
8 | 10 | ||
9 | <% button_bar do %> | 11 | <% button_bar do %> |
plugins/piwik/views/tracking-code.rhtml
@@ -4,12 +4,12 @@ | @@ -4,12 +4,12 @@ | ||
4 | _paq.push(['trackPageView']); | 4 | _paq.push(['trackPageView']); |
5 | _paq.push(['enableLinkTracking']); | 5 | _paq.push(['enableLinkTracking']); |
6 | (function() { | 6 | (function() { |
7 | - var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= escape_javascript locals[:domain] %>/piwik/"; | 7 | + var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= escape_javascript locals[:piwik_url] %>"; |
8 | _paq.push(['setTrackerUrl', u+'piwik.php']); | 8 | _paq.push(['setTrackerUrl', u+'piwik.php']); |
9 | _paq.push(['setSiteId', <%= escape_javascript locals[:site_id] %>]); | 9 | _paq.push(['setSiteId', <%= escape_javascript locals[:site_id] %>]); |
10 | var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; | 10 | var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; |
11 | g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); | 11 | g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); |
12 | })(); | 12 | })(); |
13 | </script> | 13 | </script> |
14 | -<noscript><p><img src="http://<%= escape_javascript locals[:domain] %>/piwik/piwik.php?idsite=<%= escape_javascript locals[:site_id] %>" style="border:0;" alt="" /></p></noscript> | 14 | +<noscript><p><img src="http://<%= escape_javascript locals[:piwik_url] %>piwik.php?idsite=<%= escape_javascript locals[:site_id] %>" style="border:0;" alt="" /></p></noscript> |
15 | <!-- End Piwik Code --> | 15 | <!-- End Piwik Code --> |