radiant / radiant-event-calendar-extension

An extension for Radiant CMS that integrates with iCal feeds and lets you display them in pages.

This URL has Read+Write access

radiant-event-calendar-extension / event_calendar_extension.rb
100755 44 lines (36 sloc) 1.661 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class EventCalendarExtension < Radiant::Extension
  version "0.8"
  description "An event calendar extension which draws events from any ical or CalDAV publishers (Google Calendar, .Mac, Darwin Calendar Server, etc.)"
  url "http://radiant.spanner.org/event_calendar"
 
  EXT_ROOT = '/admin/event_calendar'
 
  define_routes do |map|
    map.namespace :admin, :path_prefix => EXT_ROOT do |cal|
      cal.resources :calendars
      cal.resources :icals, :collection => {:refresh_all => :any}, :member => {:refresh => :put}
      cal.resources :events
    end
  end
  
  extension_config do |config|
    config.gem 'vpim'
  end
  
  def activate
    CalendarPeriod
    EventCalendarPage
    ApplicationHelper.send :include, Admin::CalendarHelper
    Page.send :include, EventCalendarTags
    UserActionObserver.instance.send :add_observer!, Calendar
    
    if Radiant::Config.table_exists? && !Radiant::Config["event_calendar.icals_path"]
      Radiant::Config["event_calendar.icals_path"] = "icals"
    end
 
    unless defined? admin.calendar
      Radiant::AdminUI.send :include, EventCalendarAdminUI
      admin.calendar = Radiant::AdminUI.load_default_calendar_regions
    end
    
    admin.tabs.add "Calendars", EXT_ROOT + "/calendars", :after => "Snippets", :visibility => [:all]
    if admin.tabs["Calendars"].respond_to?(:add_link) # that is, if the submenu extension is installed
      admin.tabs["Calendars"].add_link "calendar list", EXT_ROOT + "/calendars"
      admin.tabs["Calendars"].add_link "new subscription", EXT_ROOT + "/calendars/new"
      admin.tabs["Calendars"].add_link "refresh all", EXT_ROOT + "/icals/refresh_all"
    end
  end
end