trustlink 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -0
- data/Rakefile +4 -9
- data/lib/app/helpers/trustlink_helper.rb +14 -0
- data/lib/app/models/trustlink_config.rb +15 -0
- data/lib/app/models/trustlink_link.rb +6 -0
- data/lib/app/views/trustlink/_link.html.erb +5 -0
- data/lib/app/views/trustlink/links.html.erb +7 -0
- data/lib/generators/trustlink/migration_generator.rb +19 -0
- data/lib/generators/trustlink/templates/migration.rb +15 -0
- data/lib/generators/trustlink/views_generator.rb +10 -0
- data/lib/tasks/trustlink.rake +66 -0
- data/lib/trustlink/railtie.rb +6 -0
- data/lib/trustlink/version.rb +1 -1
- data/lib/trustlink.rb +8 -291
- metadata +76 -77
- data/lib/tasks/trustlink_tasks.rake +0 -4
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/config/application.rb +0 -23
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -29
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/environments/test.rb +0 -36
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -12
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -56
- data/test/dummy/config.ru +0 -4
- data/test/dummy/public/404.html +0 -58
- data/test/dummy/public/422.html +0 -58
- data/test/dummy/public/500.html +0 -57
- data/test/dummy/public/favicon.ico +0 -0
- data/test/test_helper.rb +0 -15
- data/test/trustlink_test.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e157417462bdd92d4e49bb88cdb5bd08eeb239db
|
4
|
+
data.tar.gz: 7dcfbab178cd6877a26a0e7afa9b08c4ada22dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72f5c1e2d6a31015da79feff594588e66a322cf22605d5c89290e964511c7e87b82e9bae254383dd1790315e407dae303584a84e01442a1ec5d7b4fd432b299d
|
7
|
+
data.tar.gz: 43177aab53f6a65f59048880db6df9a2397fd0a9580bdf5f0228fc7b28bb7b1895990e37dc9c911656643050ded255ad8dd8be10fb420c43020f297cfdd18f1e
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
##Trustlink module for Ruby On Rails
|
2
|
+
|
3
|
+
###Rewritten from scratch
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
* parsing xml file instead of php serialized string
|
7
|
+
* storing in database instead of text file
|
8
|
+
* requesting by rake task instead of checking on every page load
|
9
|
+
* customizable rails friendly erb templates
|
10
|
+
|
11
|
+
### Installation
|
12
|
+
Include the gem in your Gemfile:
|
13
|
+
```ruby
|
14
|
+
gem "trustlink"
|
15
|
+
```
|
16
|
+
|
17
|
+
#### preparing db
|
18
|
+
* `rails g trustlink:migration`
|
19
|
+
* `rake db:migrate`
|
20
|
+
|
21
|
+
#### generating config
|
22
|
+
* create config/trustlink.yml
|
23
|
+
```yml
|
24
|
+
key: _YOUR_TRUSTLINK_HASH_
|
25
|
+
domain: example.com
|
26
|
+
encoding: UTF-8
|
27
|
+
```
|
28
|
+
|
29
|
+
#### customizing templates (optional)
|
30
|
+
* `rails g trustlink:views`
|
31
|
+
Templates will be copied to views/trustlink folder.
|
32
|
+
|
33
|
+
#### fetching links
|
34
|
+
* `rake trustlink:fetch`
|
35
|
+
Run it by cron or use whenever gem or something other way you like.
|
36
|
+
|
37
|
+
### Notes
|
38
|
+
* In _link.html.erb first and last string inserting trustlink code recognized by trustlink bots. It should not be removed. Also important to levae url untouched.
|
39
|
+
* By default no style included. You can use styles extracted from trustlink's template. Just replace class to 'ads' used by default or use your own.
|
40
|
+
* Multi-domain feature currently not supported. Ask if you need.
|
41
|
+
|
42
|
+
For more information please follow http://www.trustlink.ru/
|
43
|
+
|
44
|
+
License
|
45
|
+
-------
|
46
|
+
This project rocks and uses MIT-LICENSE.
|
47
|
+
Copyright © 2014 Artyom Nikolaev and Trustlink
|
data/Rakefile
CHANGED
@@ -19,14 +19,9 @@ end
|
|
19
19
|
|
20
20
|
Bundler::GemHelper.install_tasks
|
21
21
|
|
22
|
-
require '
|
23
|
-
|
24
|
-
Rake::TestTask.new(:test) do |t|
|
25
|
-
t.libs << 'lib'
|
26
|
-
t.libs << 'test'
|
27
|
-
t.pattern = 'test/**/*_test.rb'
|
28
|
-
t.verbose = false
|
29
|
-
end
|
22
|
+
require 'rspec/core/rake_task'
|
30
23
|
|
24
|
+
RSpec::Core::RakeTask.new('spec')
|
31
25
|
|
32
|
-
|
26
|
+
# If you want to make this the default task
|
27
|
+
task default: :spec
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'domainatrix'
|
2
|
+
|
3
|
+
module TrustlinkHelper
|
4
|
+
def trustlink_links
|
5
|
+
options = { links: TrustlinkLink.where(page: request.path) }
|
6
|
+
if TrustlinkConfig.bot_ips.include?(request.remote_addr)
|
7
|
+
options.merge!(start: TrustlinkConfig.start_code)
|
8
|
+
options.merge!(stop: TrustlinkConfig.stop_code)
|
9
|
+
end
|
10
|
+
render template: 'trustlink/links', locals: options
|
11
|
+
rescue Exception => e
|
12
|
+
"<!-- ERROR: #{e.message} -->".html_safe
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Trustlink::MigrationGenerator < Rails::Generators::Base
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
if ActiveRecord::Base.timestamped_migrations
|
10
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
11
|
+
else
|
12
|
+
sprintf('%.3d', (current_migration_number(dirname) + 1))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_migration_file
|
17
|
+
migration_template 'migration.rb', 'db/migrate/create_trustlink_storage.rb'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateTrustlinkStorage < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :trustlink_configs do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :value
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :trustlink_links do |t|
|
9
|
+
t.string :page
|
10
|
+
t.string :anchor
|
11
|
+
t.string :text
|
12
|
+
t.string :url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Trustlink::ViewsGenerator < Rails::Generators::Base
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
public_task :copy_views
|
5
|
+
source_root File.expand_path('../../../app/views', __FILE__)
|
6
|
+
|
7
|
+
def copy_views
|
8
|
+
directory 'trustlink', 'app/views/trustlink'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
namespace :trustlink do
|
5
|
+
def say text
|
6
|
+
if Rails.env.development?
|
7
|
+
puts text
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Fetch links from server"
|
12
|
+
task fetch: :environment do
|
13
|
+
begin
|
14
|
+
config = YAML.load_file('config/trustlink.yml')
|
15
|
+
rescue Errno::ENOENT
|
16
|
+
fail "Config file not found (config/trustlink.yml)"
|
17
|
+
end
|
18
|
+
|
19
|
+
key = config['key']
|
20
|
+
domain = config['domain'].downcase
|
21
|
+
encoding = config['encoding'].upcase || 'UTF-8'
|
22
|
+
server = config['server'] || 'db.trustlink.ru'
|
23
|
+
|
24
|
+
url = "http://#{server}/#{key}/#{domain}/#{encoding}.xml"
|
25
|
+
begin
|
26
|
+
data = open(url)
|
27
|
+
rescue OpenURI::HTTPError
|
28
|
+
fail "Could not receive data"
|
29
|
+
end
|
30
|
+
|
31
|
+
root = Nokogiri::XML(data.read).root
|
32
|
+
|
33
|
+
bot_ips = root.xpath('bot_ips/ip')
|
34
|
+
configs = root.xpath('config/item')
|
35
|
+
pages = root.xpath('pages/page')
|
36
|
+
|
37
|
+
if pages.any?
|
38
|
+
TrustlinkConfig.delete_all
|
39
|
+
TrustlinkLink.delete_all
|
40
|
+
|
41
|
+
say "Ips:"
|
42
|
+
bot_ips.each do |ip|
|
43
|
+
TrustlinkConfig.create name: 'ip', value: ip.text
|
44
|
+
say "Added #{ip.text}"
|
45
|
+
end
|
46
|
+
|
47
|
+
say "Config"
|
48
|
+
configs.each do |item|
|
49
|
+
TrustlinkConfig.create name: item['name'], value: item.text
|
50
|
+
say "Added #{item['name']} = #{item.text}"
|
51
|
+
end
|
52
|
+
|
53
|
+
say "Links"
|
54
|
+
pages.each do |page|
|
55
|
+
say "Page: #{page['url']}"
|
56
|
+
page.xpath('link').each do |item|
|
57
|
+
anchor = item.at_xpath('anchor').text
|
58
|
+
text = item.at_xpath('text').text
|
59
|
+
url = item.at_xpath('url').text
|
60
|
+
TrustlinkLink.create page: page['url'], anchor: anchor, text: text, url: url
|
61
|
+
say " Added #{anchor} #{text} #{url}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/trustlink/version.rb
CHANGED
data/lib/trustlink.rb
CHANGED
@@ -1,295 +1,12 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'net/http'
|
3
|
-
require 'php_serialize'
|
4
|
-
|
5
1
|
module Trustlink
|
6
|
-
|
7
|
-
|
8
|
-
VERSION = 'T0.0.1'
|
9
|
-
DEBUG = false
|
10
|
-
TEST_COUNT = 4
|
11
|
-
TEMPLATE = 'template'
|
12
|
-
USE_SSL = false
|
13
|
-
SERVER = 'db.trustlink.ru'
|
14
|
-
CACHE_LIFETIME = 3600
|
15
|
-
CACHE_RELOADTIME = 300
|
16
|
-
|
17
|
-
class << self; attr_accessor :app_folder, :data_folder, :data, :charset, :host, :force_show_code, :multi_site, :is_static, :tl_user, :verbose, :test end
|
18
|
-
|
19
|
-
attr_accessor :links, :links_page, :request_uri, :request, :error, :file_change_date, :file_size, :links_delimiter, :links_count, :isrobot, :skip_load_links
|
20
|
-
|
21
|
-
def initialize user, request, options = {}
|
22
|
-
@app_folder = Rails.root
|
23
|
-
@data_folder = 'public'
|
24
|
-
@data = ''
|
25
|
-
@charset = 'UTF-8'
|
26
|
-
@host = ''
|
27
|
-
@force_show_code = false
|
28
|
-
@multi_site = false
|
29
|
-
@is_static = false
|
30
|
-
@tl_user = ''
|
31
|
-
@verbose = false
|
32
|
-
@test = false
|
33
|
-
self.isrobot = false
|
34
|
-
host = nil
|
35
|
-
self.request=request
|
36
|
-
@tl_user=user
|
37
|
-
|
38
|
-
raise_error("User is not defined") && return if @tl_user.blank?
|
39
|
-
raise_error("Request env is not provided") && return if @request.blank?
|
40
|
-
|
41
|
-
unless options.is_a?(Hash)
|
42
|
-
host = options
|
43
|
-
options = {}
|
44
|
-
end
|
45
|
-
|
46
|
-
host ||= options[:host]
|
47
|
-
|
48
|
-
@host = host.present? ? host : (self.request.host rescue nil)
|
49
|
-
@host = @host.gsub(/^https?:\/\//i, '').gsub(/^www\./i, '').downcase if @host.present?
|
50
|
-
|
51
|
-
@is_static = options[:is_static].present?
|
52
|
-
|
53
|
-
self.request_uri = options[:request_uri].present? ? options[:request_uri] : (self.request.path rescue nil)
|
54
|
-
self.request_uri = self.request_uri.gsub(/\?.*$/, '').gsub(/\/+/, '/') if @is_static && self.request_uri.present?
|
55
|
-
|
56
|
-
|
57
|
-
@app_folder = options[:app_folder] if options[:app_folder].present?
|
58
|
-
@data_folder = options[:data_folder] if options[:data_folder].present?
|
59
|
-
@multi_site = options[:multi_site].present?
|
60
|
-
@verbose = options[:verbose].present? || (self.links['__trustlink_debug__'].present? rescue false)
|
61
|
-
@charset = options[:charset] if options[:charset].present?
|
62
|
-
self.skip_load_links = options[:skip_load_links] if options[:skip_load_links].present?
|
63
|
-
@force_show_code = options[:force_show_code].present? || (self.links['__trustlink_debug__'].present? rescue false)
|
64
|
-
|
65
|
-
if self.request.env['HTTP_TRUSTLINK'] == @tl_user
|
66
|
-
@test = true
|
67
|
-
self.isrobot = true
|
68
|
-
@verbose = true
|
69
|
-
end
|
70
|
-
|
71
|
-
if self.request.parameters['trustlink_test'] == @tl_user
|
72
|
-
@force_show_code=true
|
73
|
-
@verbose = true
|
74
|
-
end
|
75
|
-
|
76
|
-
self.load_links unless self.skip_load_links
|
77
|
-
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
def load_links
|
82
|
-
links_db_file = File.join(@app_folder, @data_folder, @tl_user, '/trustlink.links.db')
|
83
|
-
links_db_file = File.join(@app_folder, @data_folder, @tl_user, '/trustlink.'+@host+'.links.db') if @multi_site
|
84
|
-
|
85
|
-
if !File.exist?(links_db_file)
|
86
|
-
begin
|
87
|
-
if FileUtils.touch(links_db_file)
|
88
|
-
File.utime(Time.now, Time.now - CACHE_LIFETIME,links_db_file)
|
89
|
-
File.chmod(0666, links_db_file);
|
90
|
-
else
|
91
|
-
return self.raise_error("There is no file "+links_db_file+". Fail to create. Set mode to 777 on the folder.")
|
92
|
-
end
|
93
|
-
rescue Errno::ENOENT
|
94
|
-
return self.raise_error("Can't create #{links_db_file} file. Check if #{@user} folder exist in #{@data_folder}.")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
if !File.writable?(links_db_file)
|
99
|
-
self.raise_error("There is no permissions to write: "+links_db_file+"! Set mode to 777 on the folder.")
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
if File.mtime(links_db_file) < (Time.now-CACHE_LIFETIME) || (File.mtime(links_db_file) < (Time.now-CACHE_RELOADTIME) && (File.size(links_db_file) == 0))
|
104
|
-
FileUtils.touch(links_db_file)
|
105
|
-
|
106
|
-
path = '/'+@tl_user+'/'+@host.downcase+'/'+@charset.upcase
|
107
|
-
|
108
|
-
if links = self.fetch_remote_file(SERVER, path)
|
109
|
-
if links[0,12] == 'FATAL ERROR:'
|
110
|
-
self.raise_error(links)
|
111
|
-
else
|
112
|
-
if !(@data = PHP.unserialize(links))
|
113
|
-
self.links = {}
|
114
|
-
self.raise_error("Cann't unserialize data from file.")
|
115
|
-
end
|
116
|
-
self.write(links_db_file, @data)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
@data = self.read(links_db_file) if @data.blank?
|
122
|
-
self.links = @data
|
123
|
-
|
124
|
-
if self.links.blank?
|
125
|
-
self.links = {}
|
126
|
-
self.raise_error("Empty file.")
|
127
|
-
end
|
128
|
-
|
129
|
-
self.file_change_date = File.mtime(links_db_file)
|
130
|
-
self.file_size = self.links.size
|
131
|
-
self.links_page = []
|
132
|
-
|
133
|
-
if @test
|
134
|
-
TEST_COUNT.times do
|
135
|
-
self.links_page << self.links['__test_tl_link__']
|
136
|
-
end
|
137
|
-
else
|
138
|
-
self.links_page = self.links[self.request_uri]
|
139
|
-
self.links_page = [] if self.links_page.blank?
|
140
|
-
end
|
141
|
-
|
142
|
-
self.links_count = self.links_page.size
|
143
|
-
end
|
144
|
-
|
145
|
-
def build_links n = nil
|
146
|
-
|
147
|
-
return self.error if has_errors?
|
148
|
-
|
149
|
-
total_page_links = self.links_page.size
|
150
|
-
|
151
|
-
n = total_page_links if n.to_i<=0 || n.to_i > total_page_links
|
152
|
-
|
153
|
-
res_links = self.links_page[0,n.to_i]
|
154
|
-
|
155
|
-
result = ''
|
156
|
-
|
157
|
-
if self.links['__trustlink_start__'].present? && ((self.links['__trustlink_robots__'] || []).include?(self.request.remote_addr) || @force_show_code)
|
158
|
-
result += self.links['__trustlink_start__']
|
159
|
-
end
|
160
|
-
|
161
|
-
begin
|
162
|
-
tpl_filename = File.join(@app_folder, @data_folder, @tl_user, TEMPLATE+'.tpl.html')
|
163
|
-
tpl = read_raw(tpl_filename)
|
164
|
-
rescue Errno::ENOENT
|
165
|
-
raise_error("Template file not found")
|
166
|
-
return self.error
|
167
|
-
end
|
168
|
-
|
169
|
-
block = ''
|
170
|
-
if !tpl=~/\<\{block\}\>.+\<\{\/block\}\>/
|
171
|
-
raise_error("Wrong template format: no <{block}><{/block}> tags")
|
172
|
-
else
|
173
|
-
tpl.sub!(/\<\{block\}\>(.+)\<\{\/block\}\>/im){block = $1; '%s'}
|
174
|
-
raise_error("Wrong template format: no <{head_block}> tag.") if !block.include?('<{head_block}>')
|
175
|
-
raise_error("Wrong template format: no <{/head_block}> tag.") if !block.include?('<{/head_block}>')
|
176
|
-
raise_error("Wrong template format: no <{link}> tag.") if !block.include?('<{link}>')
|
177
|
-
raise_error("Wrong template format: no <{text}> tag.") if !block.include?('<{text}>')
|
178
|
-
raise_error("Wrong template format: no <{host}> tag.") if !block.include?('<{host}>')
|
179
|
-
end
|
180
|
-
|
181
|
-
links_block = ''
|
182
|
-
|
183
|
-
res_links.each do |link|
|
184
|
-
raise_error("format of link must be an array('anchor'=>anchor,'url'=>url,'text'=>text") if link.blank? || link['text'].blank? || link['url'].blank?
|
185
|
-
parsed_host=extract_host(link['url'])
|
186
|
-
if parsed_host.blank?
|
187
|
-
raise_error("wrong format of url: "+link['url'])
|
188
|
-
else
|
189
|
-
level=parsed_host.split('.').size
|
190
|
-
raise_error("wrong host: #{parsed_host} in url #{link['url']}") if level<2
|
191
|
-
end
|
192
|
-
unless has_errors?
|
193
|
-
host=parsed_host.sub('www.','').downcase
|
194
|
-
tmp_block = block.sub("<{host}>", host)
|
195
|
-
if link['anchor'].blank?
|
196
|
-
tmp_block.sub!(/\<\{head_block\}\>(.+)\<\{\/head_block\}\>/is, "")
|
197
|
-
else
|
198
|
-
href = link['punicode_url'].blank? ? link['url'] : link['punicode_url']
|
199
|
-
tmp_block.sub!("<{link}>", '<a href="'+href+'">'+link['anchor']+'</a>')
|
200
|
-
tmp_block.sub!("<{head_block}>", '')
|
201
|
-
tmp_block.sub!("<{/head_block}>", '')
|
202
|
-
end
|
203
|
-
tmp_block.sub!("<{text}>", link['text'])
|
204
|
-
links_block << tmp_block
|
205
|
-
else
|
206
|
-
result += self.error
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
if (self.links['__trustlink_robots__'] || []).include?(self.request.remote_addr) || @verbose
|
211
|
-
|
212
|
-
result += self.error.to_s
|
213
|
-
|
214
|
-
result += '<!--REQUEST_URI='+self.request.path+"-->\n"
|
215
|
-
result += "\n<!--\n"
|
216
|
-
result += 'L '+VERSION+"\n"
|
217
|
-
result += 'REMOTE_ADDR='+self.request.remote_addr+"\n"
|
218
|
-
result += 'request_uri='+self.request_uri+"\n"
|
219
|
-
result += 'charset='+@charset+"\n"
|
220
|
-
result += 'is_static='+@is_static.to_s+"\n"
|
221
|
-
result += 'multi_site='+@multi_site.to_s+"\n"
|
222
|
-
result += 'file change date='+self.file_change_date.to_s+"\n"
|
223
|
-
result += 'lc_file_size='+self.file_size.to_s+"\n"
|
224
|
-
result += 'lc_links_count='+self.links_count.to_s+"\n"
|
225
|
-
result += 'left_links_count='+self.links_page.size.to_s+"\n"
|
226
|
-
result += 'n='+n.to_s+"\n"
|
227
|
-
result += '-->'
|
228
|
-
end
|
229
|
-
|
230
|
-
if res_links.present? && res_links.size>0
|
231
|
-
tpl = sprintf(tpl, links_block)
|
232
|
-
result += tpl
|
233
|
-
end
|
234
|
-
|
235
|
-
if self.links['__trustlink_end__'].present? && ((self.links['__trustlink_robots__'] || []).include?(self.request.remote_addr) || @force_show_code)
|
236
|
-
result += self.links['__trustlink_end__']
|
237
|
-
end
|
238
|
-
|
239
|
-
result = '<noindex>'+result+'</noindex>' if (@test && !self.isrobot)
|
240
|
-
|
241
|
-
result.force_encoding(@charset)
|
242
|
-
end
|
243
|
-
|
244
|
-
|
245
|
-
def fetch_remote_file host, path
|
246
|
-
user_agent = 'Trustlink Client RoR ' + VERSION
|
247
|
-
resp=Net::HTTP.start(host) { |http|
|
248
|
-
http.get(path)
|
249
|
-
}
|
250
|
-
if resp.body
|
251
|
-
resp.body.force_encoding(@charset)
|
252
|
-
else
|
253
|
-
self.raise_error("Can't connect to server: "+host+path)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
|
258
|
-
def read filename
|
259
|
-
Marshal.load(read_raw filename)
|
260
|
-
end
|
261
|
-
|
262
|
-
def read_raw filename
|
263
|
-
open(filename, "rb") { |file|
|
264
|
-
file.read
|
265
|
-
}
|
266
|
-
end
|
267
|
-
|
268
|
-
def write filename, data
|
269
|
-
write_raw(filename, Marshal.dump(data))
|
270
|
-
end
|
271
|
-
|
272
|
-
def write_raw filename, data
|
273
|
-
open(filename, "wb") { |file|
|
274
|
-
file.write(data)
|
275
|
-
}
|
276
|
-
end
|
277
|
-
|
278
|
-
def raise_error msg
|
279
|
-
self.error ||= ''
|
280
|
-
self.error << "<!--ERROR: #{msg}-->\n"
|
281
|
-
end
|
2
|
+
require 'trustlink/railtie' if defined?(Rails)
|
3
|
+
require 'app/helpers/trustlink_helper'
|
282
4
|
|
283
|
-
|
284
|
-
|
285
|
-
end
|
5
|
+
path = File.join(File.dirname(__FILE__), 'app', 'models')
|
6
|
+
$LOAD_PATH << path
|
286
7
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
""
|
292
|
-
end
|
293
|
-
end
|
294
|
-
end
|
8
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
9
|
+
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
10
|
+
ActionView::Base.send :include, TrustlinkHelper
|
11
|
+
ActionController::Base.prepend_view_path File.join(File.dirname(__FILE__), 'app/views')
|
295
12
|
end
|