Module: Vortex

Defined in:
lib/vrtx.rb

Overview

Utilities for communicating with the Vortex CMS through the WebDAV server interface

Defined Under Namespace

Classes: Article

Class Method Summary collapse

Class Method Details

.davUrl2webUrl(url) ⇒ Object

Convert WebDAV URL to public web URL Examples:

davUrl2webUrl("https://www-dav.uio.no/faq/it/basware.xml") =>  "http://www.uio.no/faq/it/basware.xml"


84
85
86
87
88
# File 'lib/vrtx.rb', line 84

def self.davUrl2webUrl(url)
  if(url =~ /^https:\/\/([^\/]*)-dav(\..*)/)then
    return "http://" + $1 + $2
  end
end

.parse_datestring(datestring) ⇒ Object

Parse datestring Example:

Recognizes "19.04.2009 12:00"


101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vrtx.rb', line 101

def self.parse_datestring(datestring)
  # puts "DEBUG:" + datestring.class.to_s

  if(datestring =~ /\d\d\.\d\d\.\d\d\d\d \d\d:\d\d/)then
    date = DateTime.strptime(datestring, "%d.%m.%Y %H:%M")
    # Regexp'en er et hack for å unngå at kl. 12:00 som input returnerer kl.14:00.
    # Denne koden virker bare i norge. Trenger en måte å få lest ut tidssone på.
    time = Time.parse(date.to_s.gsub(/\+00:00/,"+02:00"))
    return time
  end

  return Time.parse(datestring)
end

.publish_article(url, title, introduction, content, published_date, *args) ⇒ Object

Publish article to Vortex CMS through WebDAV server.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/vrtx.rb', line 116

def self.publish_article(url, title, introduction, content, published_date, *args)

  if(not published_date)then
    published_date = Time.now
  end
  if(published_date.class == String )
    published_date = self.parse_datestring(published_date)
  end
  if(not title)then
    title = ""
  end

  if(content =~ /\<html/ ) then
    html = content
  else
    html = ARTICLE_HTML.gsub(/##title##/, title).gsub(/##content##/, content)
  end

  properties = ARTICLE_PROPERTIES.gsub(/##published-date##/, published_date.httpdate.to_s)
  properties = properties.gsub(/##usertitle##/, title)

  characterEncoding = $defaultCharacterEncoding

  if(args)then
    options = args[0]

    if(options[:visualProfile] != nil and options[:visualProfile]== false)
      # Default is true
      properties += "<disabled xmlns=\"http://www.uio.no/visual-profile\">true</disabled>"
    end

    if(options[:authors])then
      properties += AUTHORS.gsub(/##realname##/, options[:authors])
    end

    if(options[:owner])then
      owner = options[:owner]
      if(not owner =~ /@/)then
        owner = owner + "@uio.no"
      end
      properties += "<v:owner xmlns:v=\"vrtx\">#{owner}</v:owner>"
    end

    if(options[:createdBy])then
      createdBy = options[:createdBy]
      if(not createdBy =~ /@/)then
        createdBy = createdBy + "@uio.no"
      end
      properties += "<v:createdBy xmlns:v=\"vrtx\">#{createdBy}</v:createdBy>"
    end

    if(options[:contentModifiedBy])then
      contentModifiedBy = options[:contentModifiedBy]
      if(not contentModifiedBy =~ /@/)then
        contentModifiedBy = contentModifiedBy + "@uio.no"
      end
      properties += "<v:contentModifiedBy xmlns:v=\"vrtx\">#{contentModifiedBy}</v:contentModifiedBy>"
    end

    if(options[:propertiesModifiedBy])then
      propertiesModifiedBy = options[:propertiesModifiedBy]
      if(not propertiesModifiedBy =~ /@/)then
        propertiesModifiedBy = propertiesModifiedBy + "@uio.no"
      end
      properties += "<v:propertiesModifiedBy xmlns:v=\"vrtx\">#{propertiesModifiedBy}</v:propertiesModifiedBy>"
    end

    if(options[:modifiedBy])then
      modifiedBy = options[:modifiedBy]
      if(not modifiedBy =~ /@/)then
        modifiedBy = modifiedBy + "@uio.no"
      end
      properties += "<v:contentModifiedBy xmlns:v=\"vrtx\">#{modifiedBy}</v:contentModifiedBy>"
      properties += "<v:propertiesModifiedBy xmlns:v=\"vrtx\">#{modifiedBy}</v:propertiesModifiedBy>"
    end

    if(options[:characterEncoding])then
      characterEncoding = options[:characterEncoding]
    end

    if(options[:contentLastModified])then
      contentLastModified = options[:contentLastModified]
      if(contentLastModified.class == String )
        contentLastModified = self.parse_datestring(contentLastModified)
      end
      properties += "<v:contentLastModified xmlns:v=\"vrtx\">#{contentLastModified.httpdate.to_s}</v:contentLastModified>"
    end


    if(options[:propertiesLastModified])then
      propertiesLastModified = options[:propertiesLastModified]
      if(propertiesLastModified.class == String )
        propertiesLastModified = self.parse_datestring(propertiesLastModified)
      end
      properties += "<v:propertiesLastModified xmlns:v=\"vrtx\">#{propertiesLastModified.httpdate.to_s}</v:propertiesLastModified>"
    end

    if(options[:creationDate])then
      creationDate = options[:creationDate]

      if(creationDate.class == Time)then
        creationDateString = creationDate.httpdate.to_s ## xmlschema.to_s
      end

      if(creationDate.class == String)then
        creationDateString = parse_datestring(creationDate).httpdate.to_s
      end

      properties += "<v:creationTime>#{creationDateString}</v:creationTime>"
    end

  end

  properties = properties.gsub(/##characterEncoding##/, characterEncoding )

  if(introduction) then
    if(not introduction =~ /^<p>/)then
      introduction = "<p>" + introduction + "</p>"
    end
    introduction = introduction.gsub(/</,"&lt;").gsub(/>/,"&gt;")
    properties = properties + INTRODUCTION.gsub(/##introduction##/, introduction)
    properties = properties.gsub("\n","").gsub(/ +/," ")
  end

  properties = properties.gsub("&amp;","&amp;&amp;")
  # puts "Properties: " + properties

  WebDAV.publish(url, html, properties )
  return true
end

.url2davUrl(url) ⇒ Object

Convert public/non-webdav url’s to vortex-webdav-url’s



91
92
93
94
95
# File 'lib/vrtx.rb', line 91

def self.url2davUrl(url)
  if(url =~ /^http:\/\/([^.]*)(\..*)/) then
    return "https://" + $1 + "-dav" + $2
  end
end