EliteJournal 1.9.400

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/AUTHORS +1 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +22 -0
  4. data/app/controllers/account_controller.rb +25 -0
  5. data/app/controllers/application.rb +83 -0
  6. data/app/controllers/atom_controller.rb +26 -0
  7. data/app/controllers/auth_controller.rb +23 -0
  8. data/app/controllers/backend_controller.rb +14 -0
  9. data/app/controllers/css_controller.rb +31 -0
  10. data/app/controllers/draft_controller.rb +62 -0
  11. data/app/controllers/image_controller.rb +11 -0
  12. data/app/controllers/journal_controller.rb +53 -0
  13. data/app/controllers/link_controller.rb +29 -0
  14. data/app/controllers/ping_controller.rb +44 -0
  15. data/app/controllers/post_controller.rb +131 -0
  16. data/app/controllers/rss_controller.rb +22 -0
  17. data/app/controllers/tags_controller.rb +74 -0
  18. data/app/controllers/user_controller.rb +30 -0
  19. data/app/controllers/users_controller.rb +13 -0
  20. data/app/helpers/account_helper.rb +2 -0
  21. data/app/helpers/application_helper.rb +117 -0
  22. data/app/helpers/atom_helper.rb +2 -0
  23. data/app/helpers/auth_helper.rb +2 -0
  24. data/app/helpers/backend_helper.rb +2 -0
  25. data/app/helpers/css_helper.rb +2 -0
  26. data/app/helpers/draft_helper.rb +2 -0
  27. data/app/helpers/image_helper.rb +2 -0
  28. data/app/helpers/journal_helper.rb +2 -0
  29. data/app/helpers/link_helper.rb +2 -0
  30. data/app/helpers/ping_helper.rb +5 -0
  31. data/app/helpers/post_helper.rb +2 -0
  32. data/app/helpers/rss_helper.rb +5 -0
  33. data/app/helpers/tags_helper.rb +7 -0
  34. data/app/helpers/user_helper.rb +2 -0
  35. data/app/helpers/users_helper.rb +2 -0
  36. data/app/models/blogger_api.rb +24 -0
  37. data/app/models/comment.rb +18 -0
  38. data/app/models/draft.rb +12 -0
  39. data/app/models/face.rb +24 -0
  40. data/app/models/feed_killer.rb +17 -0
  41. data/app/models/image.rb +7 -0
  42. data/app/models/link.rb +10 -0
  43. data/app/models/meta_weblog_api.rb +82 -0
  44. data/app/models/ping.rb +16 -0
  45. data/app/models/post.rb +30 -0
  46. data/app/models/stylesheet.rb +7 -0
  47. data/app/models/tag.rb +16 -0
  48. data/app/models/user.rb +35 -0
  49. data/app/views/account/info.rhtml +30 -0
  50. data/app/views/atom/feed.rxml +15 -0
  51. data/app/views/auth/login.rhtml +9 -0
  52. data/app/views/css/edit.rhtml +18 -0
  53. data/app/views/css/list.rhtml +24 -0
  54. data/app/views/css/new.rhtml +6 -0
  55. data/app/views/draft/edit.rhtml +9 -0
  56. data/app/views/draft/list.rhtml +22 -0
  57. data/app/views/draft/new.rhtml +9 -0
  58. data/app/views/journal/_comment.rhtml +10 -0
  59. data/app/views/journal/_post.rhtml +40 -0
  60. data/app/views/journal/_trackback.rhtml +4 -0
  61. data/app/views/journal/error.rhtml +1 -0
  62. data/app/views/journal/index.rhtml +1 -0
  63. data/app/views/journal/view.rhtml +15 -0
  64. data/app/views/layouts/application.rhtml +90 -0
  65. data/app/views/link/list.rhtml +19 -0
  66. data/app/views/link/new.rhtml +7 -0
  67. data/app/views/ping/trackback.rxml +4 -0
  68. data/app/views/post/_reply.rhtml +10 -0
  69. data/app/views/post/destroyxml.rxml +3 -0
  70. data/app/views/post/edit.rhtml +7 -0
  71. data/app/views/post/new.rhtml +13 -0
  72. data/app/views/post/postxml.rxml +7 -0
  73. data/app/views/post/reply.rhtml +33 -0
  74. data/app/views/post/replyxml.rxml +5 -0
  75. data/app/views/post/toggle_commentingxml.rxml +9 -0
  76. data/app/views/rss/index.rxml +15 -0
  77. data/app/views/tags/addxml.rxml +4 -0
  78. data/app/views/tags/index.rhtml +3 -0
  79. data/app/views/tags/no_completions.rhtml +1 -0
  80. data/app/views/tags/search.rhtml +10 -0
  81. data/app/views/tags/search_completer.rhtml +1 -0
  82. data/app/views/user/list.rhtml +21 -0
  83. data/app/views/user/new.rhtml +12 -0
  84. data/app/views/users/index.rhtml +6 -0
  85. data/config/app.yml +15 -0
  86. data/config/database.yml +17 -0
  87. data/config/environment.rb +58 -0
  88. data/config/environments/development.rb +5 -0
  89. data/config/environments/geminstall.rb +4 -0
  90. data/config/environments/production.rb +3 -0
  91. data/config/environments/shared.rb +17 -0
  92. data/config/environments/test.rb +3 -0
  93. data/db/db-mysql.sql +95 -0
  94. data/db/db-postgresql.sql +94 -0
  95. data/db/db-sqlite.sql +94 -0
  96. data/db/default_user.sql +1 -0
  97. data/db/development_structure.sql +257 -0
  98. data/elitejournal +132 -0
  99. data/lib/image_size.rb +277 -0
  100. data/lib/trackback.rb +45 -0
  101. data/public/404.html +6 -0
  102. data/public/500.html +6 -0
  103. data/public/dispatch.cgi +10 -0
  104. data/public/dispatch.fcgi +7 -0
  105. data/public/dispatch.rb +10 -0
  106. data/public/stylesheets/ej-layout.css +126 -0
  107. data/public/stylesheets/ej-style.css +105 -0
  108. data/public/stylesheets/undohtml.css +9 -0
  109. metadata +178 -0
@@ -0,0 +1,131 @@
1
+ require_dependency 'trackback'
2
+
3
+ class PostController < ApplicationController
4
+ before_filter :auth_required, :except => :reply
5
+ cache_sweeper :feed_killer, :only => [:new, :edit, :destroy, :destroyxml]
6
+
7
+ def index
8
+ redirect_to :action => 'new'
9
+ end
10
+
11
+ def new
12
+ @post = Post.new
13
+
14
+ if @request.post?
15
+ @post.attributes = @params['post']
16
+ @post.user = current_user
17
+ @post.allows_comment = current_user.allows_comment?
18
+ if @post.save
19
+ # Hook up the tags
20
+ unless @params['tags'].empty?
21
+ @params['tags'].split(',').collect {|t| t.strip}.uniq.each do |tag|
22
+ thetag = Tag.find_by_tag(tag) || Tag.new('tag' => tag)
23
+ thetag.increment('numitems')
24
+ thetag.save
25
+ @post.tags << thetag
26
+ end
27
+ end
28
+ # Check for trackback.
29
+ send_trackback(@post, @params['tb_url'], @app_config) unless @params['tb_url'].empty?
30
+ redirect_to :controller => 'users', :action => @post.user.username
31
+ return
32
+ end
33
+ @error = @post.errors.full_messages
34
+ return
35
+ end
36
+ end
37
+
38
+ def edit
39
+ begin
40
+ @post = current_user.posts.find(@params['id'])
41
+ rescue ActiveRecord::RecordNotFound
42
+ redirect_to_main
43
+ return
44
+ end
45
+
46
+ if @request.post?
47
+ @post.attributes = @params['post']
48
+ if @post.save
49
+ flash['notice'] = "Post was successfully saved."
50
+ redirect_to_main
51
+ end
52
+ end
53
+ end
54
+
55
+ def postxml
56
+ @post = current_user.posts.find(@params['id']) rescue Post.new
57
+ @post.update_attributes @params['post'] if @request.post?
58
+ render_without_layout 'post/postxml'
59
+ end
60
+
61
+ def destroy
62
+ current_user.posts.find(@params['id']).destroy rescue nil
63
+ redirect_to_main
64
+ end
65
+
66
+ def destroyxml
67
+ @postid = @params['id']
68
+ current_user.posts.find(@params['id']).destroy rescue nil
69
+ end
70
+
71
+ def destroy_comment
72
+ Comment.find(@params['id']).destroy rescue nil
73
+ redirect_to @request.env['HTTP_REFERER']
74
+ end
75
+
76
+ def toggle_commenting
77
+ if (post = current_user.posts.find(@params['id']) rescue nil)
78
+ post.allows_comment = (not post.allows_comment?)
79
+ post.save
80
+ end
81
+ redirect_to @request.env['HTTP_REFERER']
82
+ end
83
+
84
+ def toggle_commentingxml
85
+ if (@post = current_user.posts.find(@params['id']) rescue nil)
86
+ @post.allows_comment = (not @post.allows_comment?)
87
+ @post.save
88
+ end
89
+ end
90
+
91
+ def reply
92
+ begin
93
+ @post = Post.find(@params['id'])
94
+ @user = @post.user
95
+ unless @post.allows_comment?
96
+ redirect_to :controller => 'journal', :action => 'view', :id => @post.id
97
+ return
98
+ end
99
+
100
+ @comments = @post.find_all_in_comments("comment_id=0")
101
+
102
+ if @request.post?
103
+ @newcomment = @post.comments.create(@params['newcomment'])
104
+ unless @newcomment.save
105
+ @error = @newcomment.errors.full_messages
106
+ render 'journal/error'
107
+ return
108
+ end
109
+ redirect_to :controller => 'journal', :action => 'view', :id => @newcomment.post_id
110
+ return
111
+ end
112
+
113
+ # A little hack to pre-load the subject line.
114
+ # Do this down here so it doesn't get called for the POST.
115
+ @newcomment = Comment.new('subject' => 'Re: ' + @post.subject)
116
+ if @params['comment_id']
117
+ @comment = Comment.find(@params['comment_id'])
118
+ end
119
+
120
+ rescue ActiveRecord::RecordNotFound
121
+ redirect_to_main
122
+ end
123
+ end
124
+
125
+ def replyxml
126
+ @post = Post.find(@params['id'])
127
+ @params['comment']['body'].strip! # what the fuck, safari? \000?
128
+ @comment = @post.comments.create(@params['comment'])
129
+ render_without_layout 'journal/replyxml'
130
+ end
131
+ end
@@ -0,0 +1,22 @@
1
+ class RssController < ApplicationController
2
+ layout nil
3
+ caches_page :index
4
+
5
+ def index
6
+ @posts = Post.find_all(nil, 'updated_at DESC', @app_config['main']['num_posts'])
7
+ @title = @app_config['main']['title']
8
+ @subtitle = @app_config['main']['subtitle']
9
+ end
10
+
11
+ # +method_missing+ provides the convenient /atom/username URLs to
12
+ # access a user's feed. If a non-existent user is passed, it will
13
+ # just return an empty feed.
14
+ def method_missing(method)
15
+ user = User.find_by_username(method.to_s)
16
+ @title = user.title
17
+ @subtitle = user.subtitle
18
+ @posts = user.posts.find_all(nil, 'created_at desc', @app_config['main']['num_posts']) rescue []
19
+ render_action 'index'
20
+ cache_page if ActionController::Base.perform_caching
21
+ end
22
+ end
@@ -0,0 +1,74 @@
1
+ class TagsController < ApplicationController
2
+ def index
3
+ @tags = Tag.find_all(nil, 'tag')
4
+ end
5
+
6
+ def show
7
+ @tag = Tag.find_by_tag(CGI.unescape(@params['tag'])) rescue Tag.new
8
+ @posts = @tag.posts
9
+ render 'journal/index'
10
+ end
11
+
12
+ def add
13
+ post = Post.find(@params['post_id'])
14
+ post_tags = post.tags.collect { |t| t.tag }
15
+ unless @params['tags'].empty?
16
+ @params['tags'].split(',').each do |tag|
17
+ unless post_tags.include? tag.strip
18
+ thetag = Tag.find_by_tag(tag.strip) || Tag.new('tag' => tag.strip)
19
+ thetag.increment('numitems')
20
+ thetag.save
21
+ post.tags << thetag
22
+ end
23
+ end
24
+ end
25
+ redirect_to :controller => 'journal', :action => 'view', :id => post.id
26
+ end
27
+
28
+ def addxml
29
+ @post = Post.find(@params['post_id'])
30
+ post_tags = @post.tags.collect { |t| t.tag }
31
+ unless @params['tags'].empty?
32
+ @params['tags'].split(',').each do |tag|
33
+ unless post_tags.include? tag.strip
34
+ thetag = Tag.find_by_tag(tag.strip) || Tag.new('tag' => tag.strip)
35
+ thetag.increment('numitems')
36
+ thetag.save
37
+ @post.tags << thetag
38
+ end
39
+ end
40
+ end
41
+ render_without_layout 'tags/addxml'
42
+ end
43
+
44
+ def search
45
+ if @params['qu']
46
+ if /,\W*$/ =~ @params['qu']
47
+ render_without_layout 'tags/no_completions'
48
+ return
49
+ end
50
+
51
+ items = @params['qu'].split(',')
52
+ item = items[-1].strip
53
+
54
+ if items.length > 1
55
+ notin = "AND tag NOT IN ("
56
+ notin += items[0...-1].collect {|t| "'#{t.strip}'"}.join(',') + ")"
57
+ else
58
+ notin = ''
59
+ end
60
+ if item != ''
61
+ @tags = Tag.find_all("tag LIKE '#{item}%' #{notin}", 'tag')
62
+ else
63
+ @tags = []
64
+ end
65
+
66
+ @tagarray = @tags.collect { |t| "\"#{t.tag}\"" }.join(', ')
67
+ @postsarray = @tags.collect { |t| "\"#{t.posts_count} posts\"" }.join(', ')
68
+
69
+ render_without_layout 'tags/search_completer'
70
+ else
71
+ render_without_layout 'tags/search'
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,30 @@
1
+ class UserController < ApplicationController
2
+ before_filter :auth_required
3
+ before_filter :admin_required
4
+
5
+ def index
6
+ list
7
+ render_action 'list'
8
+ end
9
+
10
+ def list
11
+ @users = User.find_all(nil, 'name')
12
+ end
13
+
14
+ def new
15
+ @user = User.new
16
+ if @request.post?
17
+ @user.attributes = @params['user']
18
+ if @user.save
19
+ flash['notice'] = "User was successfully saved."
20
+ redirect_to_user
21
+ return
22
+ end
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ User.find(@params['id']).destroy rescue nil
28
+ redirect_to_user
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ class UsersController < ApplicationController
2
+ def index
3
+ @users = User.find_all nil, 'username'
4
+ end
5
+
6
+ def method_missing(method)
7
+ @user = User.find_by_username(method.to_s)
8
+ redirect_to_main and return unless @user
9
+ @posts = @user.posts.find_all(nil, 'created_at desc', @app_config['main']['num_posts'])
10
+
11
+ render 'journal/index'
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ module AccountHelper
2
+ end
@@ -0,0 +1,117 @@
1
+ # The methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ def link_to_year(year)
4
+ content_tag "a", year, {'href'=> @app_config['main']['app_base'] + year}
5
+ end
6
+
7
+ def link_to_month(year, month, name)
8
+ content_tag "a", name, {'href'=> @app_config['main']['app_base'] + year + '/' + month}
9
+ end
10
+
11
+ def link_to_day(year, month, day, name)
12
+ content_tag "a", name, {'href'=> @app_config['main']['app_base'] + year + '/' + month + '/' + day}
13
+ end
14
+
15
+ def sexifytime(t)
16
+ day = case t.day % 10
17
+ when 0
18
+ "#{t.day}th"
19
+ when 1
20
+ "#{t.day}st"
21
+ when 2
22
+ "#{t.day}nd"
23
+ when 3
24
+ "#{t.day}rd"
25
+ else
26
+ "#{t.day}th"
27
+ end
28
+
29
+ day = "#{t.day}th" if [12, 13, 14].include? t.day
30
+
31
+
32
+ str = ''
33
+ str << link_to_day(t.strftime('%Y'), t.strftime('%m'), t.strftime('%d'), day) << ' '
34
+ str << link_to_month(t.strftime('%Y'), t.strftime('%m'), t.strftime('%B')) << ' '
35
+ str << link_to_year(t.strftime('%Y')) << ', '
36
+
37
+ str << case t.hour
38
+ when 0..2
39
+ 'the wee hours'
40
+ when 3..6
41
+ 'terribly early in the morning'
42
+ when 7..9
43
+ 'early morning'
44
+ when 10
45
+ 'mid-morning'
46
+ when 11
47
+ 'late morning'
48
+ when 12..13
49
+ 'lunch time'
50
+ when 14
51
+ 'early afternoon'
52
+ when 15..16
53
+ 'mid-afternoon'
54
+ when 17
55
+ 'late afternoon'
56
+ when 18..19
57
+ 'early evening'
58
+ when 20..21
59
+ 'evening time'
60
+ when 22
61
+ 'late evening'
62
+ when 23
63
+ 'late at night'
64
+ end
65
+ end
66
+
67
+ def link_user(user, text=user.name)
68
+ link_to text, :controller => 'users', :action => user.username
69
+ end
70
+
71
+ def tag_links(post, limit = nil)
72
+ tags = post.tags.sort_by {|tag| tag.numitems}.reverse.map { |tag| link_to(tag.tag, :controller => 'tags', :action => 'show', :params => {'tag' => CGI.escape(tag.tag)}) }
73
+ (limit ? tags.first(limit) : tags ).join(', ')
74
+ end
75
+
76
+ def comment_toggle_link(post)
77
+ text = post.allows_comment? ? 'Disallow Comments' : 'Allow Comments'
78
+ link_to(text, {:controller => 'post', :action => 'toggle_commenting', :id => post.id}, {'onclick' => "return toggleCommenting('#{post.id}')"})
79
+ end
80
+
81
+ def post_links(post)
82
+ if post.allows_comment?
83
+ disp = ''
84
+ else
85
+ disp = 'style="display: none;"'
86
+ end
87
+
88
+ str = '<ul class="postlinks">'
89
+ str << "<li #{disp} id=\"replylink_#{post.id}\">" + link_to('Reply', {:controller => 'post', :action => 'reply', :id => post.id}, 'onclick' => "return showReply('#{post.id}')", 'id' => "post_reply_#{post.id}") + "</li>"
90
+ str << '<li>' + link_to('Add Tags', {:controller => 'post', :action => 'tag', :id => post.id}, 'onclick' => "return showTagger('#{post.id}')", 'id' => "post_tagger_#{post.id}") + '</li>'
91
+ str << '<li>' + link_to("View / Permalink", {:controller => 'view', :action => post.id.to_s}, {'class' => 'middle' }) + '</li>'
92
+ str << "<li #{disp} id=\"comment_count_#{post.id}\"> " + link_to("Comments (#{post.comments.length})", :controller => 'view', :action => post.id.to_s, :anchor => 'comments') + "</li>"
93
+ str << "<li>" + link_to("Trackbacks (#{post.pings.length})", :controller => 'view', :action => post.id.to_s, :anchor => 'trackbacks') + "</li>"
94
+ str << '</ul>'
95
+ end
96
+
97
+ def render_body(post)
98
+ unless ['view', 'reply'].include? @params['action']
99
+ return post.sections.first + (post.sections.length > 1 ? '<p><strong>Read More ...</strong></p>' : '')
100
+ end
101
+ post.rendered
102
+ end
103
+
104
+ def user_face(user)
105
+ return nil unless user.has_face?
106
+ image = %{<img class="user_face" src="/image/face/#{user.id}" height="#{user.face.height}" width="#{user.face.width}" />}
107
+ link_user(user, image)
108
+ end
109
+
110
+ def page_title()
111
+ user_page? ? @user.title : @app_config['main']['title']
112
+ end
113
+
114
+ def page_subtitle()
115
+ user_page? ? @user.subtitle : @app_config['main']['subtitle']
116
+ end
117
+ end
@@ -0,0 +1,2 @@
1
+ module AtomHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module AuthHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module BackendHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module CssHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module DraftHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ImageHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module JournalHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module LinkHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ module PingHelper
2
+ def self.append_features(controller) #:nodoc:
3
+ controller.ancestors.include?(ActionController::Base) ? controller.add_template_helper(self) : super
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module PostHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ module RssHelper
2
+ def self.append_features(controller) #:nodoc:
3
+ controller.ancestors.include?(ActionController::Base) ? controller.add_template_helper(self) : super
4
+ end
5
+ end