Class ExternalLink
In: app/models/external_link.rb
Parent: ActiveRecord::Base

External Links are html links to outside of LogiLogi

Methods

Attributes

position_ranges  [RW] 

Protected Instance methods

Sets the position_ranges attribute and associates each PositionRange with it‘s position in the un-sorted list.

[Source]

    # File app/models/external_link.rb, line 51
51:   def after_initialize
52:     if self.new_record?
53:       @position_ranges = PositionRange::List.new()
54:     else
55:       @position_ranges = PositionRange::List.from_s(self.position_ranges_string, :external_link => self)
56:     end
57:     return true
58:   end

Logs the link‘s creation to LogLog

[Source]

    # File app/models/external_link.rb, line 82
82:   def log_create_to_log_log
83:     if GlobalConfig.use_log_log
84:       m = LogLogMessage.new(
85:           :kind => "External link",
86:           :channel_names => ['all', 'external_links',
87:               'for_' + self.logi.creator.unix_name].join(','),
88:           :title => 'In: ' + self.logi.current_title,
89:           :author => self.user.name,
90:           :text => self.text + '\n' + self.url,
91:           :url => GlobalConfig.site_url + self.logi.link.to_s)
92:       m.save
93:     end
94:   end

Sets the text to the url if nil.

[Source]

    # File app/models/external_link.rb, line 74
74:   def set_text_if_nil
75:     if self.text.nil? or self.text.empty?
76:       self.text = self.url
77:     end
78:   end

Does a sanity-check on the position_ranges and turns them into a string for saving.

[Source]

    # File app/models/external_link.rb, line 63
63:   def stringify_position_ranges
64:     if !@position_ranges.below?(self.logi.text_stack.size) # sanity check
65:       raise StandardError, t('defaults.error_end_position_range_bigger') + ' ' +
66:           self.logi.text_stack.size.to_s
67:     end
68:     self.position_ranges_string = @position_ranges.to_s
69:     return true
70:   end

Validation-functions

[Source]

     # File app/models/external_link.rb, line 100
100:   def validate
101:     # no html-tags
102:     if self.text =~ Const::LogiVersion::HTML_TAG or self.url =~ Const::LogiVersion::HTML_TAG
103:       self.errors.add(:text, t('m.external_link.html_tags_not_allowed'))
104:     end
105:     if self.url =~ /#{GlobalConfig.domain}|#{GlobalConfig.domain.downcase}\/[A-Z]/ and self.url !~ /old\./
106:       self.errors.add(:url, t('m.external_link.meanth_for_only'))
107:     end
108:   end

[Validate]