Browse files

ok, for reals

  • Loading branch information...
1 parent d95b0c3 commit 7ded725a7adbc53983938ffcd9fb76b752e4cc90 Bruno Bornsztein committed Mar 25, 2008
Showing with 11,458 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +84 −0 README
  3. +22 −0 Rakefile
  4. +7 −0 about.yml
  5. +23 −0 app/controllers/admin_controller.rb
  6. +82 −0 app/controllers/ads_controller.rb
  7. +143 −0 app/controllers/application.rb
  8. +116 −0 app/controllers/categories_controller.rb
  9. +188 −0 app/controllers/clippings_controller.rb
  10. +35 −0 app/controllers/comment_sweeper.rb
  11. +138 −0 app/controllers/comments_controller.rb
  12. +86 −0 app/controllers/contests_controller.rb
  13. +68 −0 app/controllers/events_controller.rb
  14. +29 −0 app/controllers/favorite_sweeper.rb
  15. +40 −0 app/controllers/favorites_controller.rb
  16. +68 −0 app/controllers/forums_controller.rb
  17. +143 −0 app/controllers/friendships_controller.rb
  18. +76 −0 app/controllers/homepage_features_controller.rb
  19. +61 −0 app/controllers/invitations_controller.rb
  20. +68 −0 app/controllers/metro_areas_controller.rb
  21. +19 −0 app/controllers/moderators_controller.rb
  22. +20 −0 app/controllers/monitorships_controller.rb
  23. +107 −0 app/controllers/offerings_controller.rb
  24. +221 −0 app/controllers/photos_controller.rb
  25. +36 −0 app/controllers/post_sweeper.rb
  26. +216 −0 app/controllers/posts_controller.rb
  27. +131 −0 app/controllers/sb_posts_controller.rb
  28. +39 −0 app/controllers/sessions_controller.rb
  29. +24 −0 app/controllers/sitemap_controller.rb
  30. +107 −0 app/controllers/skills_controller.rb
  31. +76 −0 app/controllers/statistics_controller.rb
  32. +54 −0 app/controllers/tags_controller.rb
  33. +116 −0 app/controllers/topics_controller.rb
  34. +350 −0 app/controllers/users_controller.rb
  35. +16 −0 app/controllers/vote_sweeper.rb
  36. +24 −0 app/controllers/votes_controller.rb
  37. +9 −0 app/controllers/xmlrpc_controller.rb
  38. +2 −0 app/helpers/ads_helper.rb
  39. +73 −0 app/helpers/advertising_helper.rb
  40. +331 −0 app/helpers/application_helper.rb
  41. +2 −0 app/helpers/categories_helper.rb
  42. +2 −0 app/helpers/clippings_helper.rb
  43. +2 −0 app/helpers/comments_helper.rb
  44. +2 −0 app/helpers/contests_helper.rb
  45. +19 −0 app/helpers/forums_helper.rb
  46. +14 −0 app/helpers/friendships_helper.rb
  47. +2 −0 app/helpers/homepage_features_helper.rb
  48. +2 −0 app/helpers/invitations_helper.rb
  49. +2 −0 app/helpers/metro_areas_helper.rb
  50. +2 −0 app/helpers/moderators_helper.rb
  51. +2 −0 app/helpers/monitorships_helper.rb
  52. +2 −0 app/helpers/offerings_helper.rb
  53. +2 −0 app/helpers/photos_helper.rb
  54. +22 −0 app/helpers/posts_helper.rb
  55. +2 −0 app/helpers/sb_posts_helper.rb
  56. +2 −0 app/helpers/sessions_helper.rb
  57. +7 −0 app/helpers/sitemap_helper.rb
  58. +2 −0 app/helpers/skills_helper.rb
  59. +2 −0 app/helpers/statistics_helper.rb
  60. +2 −0 app/helpers/tags_helper.rb
  61. +2 −0 app/helpers/topics_helper.rb
  62. +22 −0 app/helpers/users_helper.rb
  63. +42 −0 app/models/ad.rb
  64. +3 −0 app/models/asset.rb
  65. +40 −0 app/models/category.rb
  66. +13 −0 app/models/choice.rb
  67. +75 −0 app/models/clipping.rb
  68. +10 −0 app/models/clipping_image.rb
  69. +85 −0 app/models/comment.rb
  70. +21 −0 app/models/contest.rb
  71. +16 −0 app/models/country.rb
  72. +34 −0 app/models/event.rb
  73. +53 −0 app/models/favorite.rb
  74. +38 −0 app/models/forum.rb
  75. +51 −0 app/models/friendship.rb
  76. +3 −0 app/models/friendship_status.rb
  77. +17 −0 app/models/homepage_feature.rb
  78. +33 −0 app/models/invitation.rb
  79. +10 −0 app/models/metro_area.rb
  80. +7 −0 app/models/moderatorship.rb
  81. +5 −0 app/models/monitorship.rb
  82. +7 −0 app/models/offering.rb
  83. +74 −0 app/models/photo.rb
  84. +44 −0 app/models/poll.rb
  85. +184 −0 app/models/post.rb
  86. +36 −0 app/models/sb_post.rb
  87. +12 −0 app/models/skill.rb
  88. +4 −0 app/models/state.rb
  89. +65 −0 app/models/topic.rb
  90. +410 −0 app/models/user.rb
  91. +113 −0 app/models/user_notifier.rb
  92. +10 −0 app/models/user_observer.rb
  93. +19 −0 app/models/vote.rb
  94. +27 −0 app/views/activities/_activity.haml
  95. +12 −0 app/views/activities/_icon.haml
  96. +63 −0 app/views/admin/users.rhtml
  97. +67 −0 app/views/ads/edit.rhtml
  98. +43 −0 app/views/ads/index.rhtml
  99. +71 −0 app/views/ads/new.rhtml
  100. +39 −0 app/views/ads/show.rhtml
  101. +32 −0 app/views/application/_about_nav.rhtml
  102. +13 −0 app/views/application/_homepage_banner_message.rhtml
  103. +18 −0 app/views/application/_homepage_feature.rhtml
  104. +52 −0 app/views/application/_homepage_features.rhtml
  105. +12 −0 app/views/application/_homepage_nav.rhtml
  106. +59 −0 app/views/application/about.rhtml
  107. +16 −0 app/views/application/advertise.rhtml
  108. +45 −0 app/views/application/faq.rhtml
  109. +3 −0 app/views/application/plaxo.haml
  110. +70 −0 app/views/application/site_index.haml
  111. +44 −0 app/views/application/teaser.rhtml
  112. +17 −0 app/views/categories/_tips.rhtml
  113. +39 −0 app/views/categories/edit.rhtml
  114. +36 −0 app/views/categories/index.rhtml
  115. +12 −0 app/views/categories/new.rhtml
  116. +76 −0 app/views/categories/show.rhtml
  117. +18 −0 app/views/clippings/_clipping.haml
  118. +3 −0 app/views/clippings/_images.rhtml
  119. +41 −0 app/views/clippings/edit.rhtml
  120. +88 −0 app/views/clippings/index.rhtml
  121. +1 −0 app/views/clippings/load_images_from_uri.rjs
  122. +43 −0 app/views/clippings/new.rhtml
  123. +154 −0 app/views/clippings/new_clipping.rhtml
  124. +63 −0 app/views/clippings/show.rhtml
  125. +37 −0 app/views/clippings/site_index.haml
  126. +37 −0 app/views/clippings/widget.rhtml
  127. +23 −0 app/views/comments/_comment.rhtml
  128. +28 −0 app/views/comments/index.rhtml
  129. +14 −0 app/views/contests/_banner.rhtml
  130. +36 −0 app/views/contests/edit.rhtml
  131. +46 −0 app/views/contests/index.rhtml
  132. +50 −0 app/views/contests/latest.rhtml
  133. +36 −0 app/views/contests/new.rhtml
  134. +33 −0 app/views/contests/show.rhtml
  135. +37 −0 app/views/events/edit.rhtml
  136. +45 −0 app/views/events/index.rhtml
  137. +38 −0 app/views/events/new.rhtml
  138. +32 −0 app/views/events/show.rhtml
  139. +5 −0 app/views/favorites/_favorite.haml
  140. +11 −0 app/views/favorites/create.rjs
  141. +6 −0 app/views/favorites/destroy.rjs
  142. +18 −0 app/views/favorites/index.haml
  143. +13 −0 app/views/favorites/show.haml
  144. +29 −0 app/views/forums/_form.rhtml
  145. +15 −0 app/views/forums/edit.rhtml
  146. +80 −0 app/views/forums/index.rhtml
  147. +10 −0 app/views/forums/new.rhtml
  148. +104 −0 app/views/forums/show.rhtml
  149. +163 −0 app/views/friendships/_browser.rhtml
  150. +14 −0 app/views/friendships/_friendships.rhtml
  151. +22 −0 app/views/friendships/accepted.rhtml
  152. +15 −0 app/views/friendships/denied.rhtml
  153. +12 −0 app/views/friendships/edit.rhtml
  154. +4 −0 app/views/friendships/index.rhtml
  155. +29 −0 app/views/friendships/index.rxml
  156. +15 −0 app/views/friendships/pending.rhtml
  157. +8 −0 app/views/friendships/show.rhtml
  158. +35 −0 app/views/homepage_features/edit.rhtml
  159. +44 −0 app/views/homepage_features/index.rhtml
  160. +34 −0 app/views/homepage_features/new.rhtml
  161. +33 −0 app/views/homepage_features/show.rhtml
  162. +10 −0 app/views/invitations/edit.rhtml
  163. +18 −0 app/views/invitations/index.rhtml
  164. +15 −0 app/views/invitations/new.rhtml
  165. +3 −0 app/views/invitations/show.rhtml
  166. +8 −0 app/views/layouts/_post.rxml
  167. +30 −0 app/views/layouts/_scripts_and_styles.rhtml
  168. +120 −0 app/views/layouts/application.rhtml
  169. +36 −0 app/views/layouts/beta.rhtml
  170. +24 −0 app/views/metro_areas/edit.rhtml
  171. +44 −0 app/views/metro_areas/index.rhtml
  172. +23 −0 app/views/metro_areas/new.rhtml
  173. +18 −0 app/views/metro_areas/show.rhtml
  174. +14 −0 app/views/moderators/_toggle.rhtml
  175. +5 −0 app/views/moderators/create.rjs
  176. +1 −0 app/views/moderators/destroy.rjs
  177. +4 −0 app/views/monitorships/create.rjs
  178. +4 −0 app/views/monitorships/destroy.rjs
  179. +54 −0 app/views/offerings/_chooser.rhtml
  180. +10 −0 app/views/offerings/edit.rhtml
  181. +18 −0 app/views/offerings/index.rhtml
  182. +9 −0 app/views/offerings/new.rhtml
  183. +3 −0 app/views/offerings/show.rhtml
  184. +14 −0 app/views/photos/_manage_photos.haml
  185. +10 −0 app/views/photos/_photo_profile_details.rhtml
  186. +22 −0 app/views/photos/_show_image_list.haml
  187. +48 −0 app/views/photos/edit.rhtml
  188. +43 −0 app/views/photos/index.rhtml
  189. +9 −0 app/views/photos/index.rxml
  190. +64 −0 app/views/photos/inline_new.rhtml
  191. +1 −0 app/views/photos/manage_photos.rjs
  192. +73 −0 app/views/photos/new.rhtml
  193. +8 −0 app/views/photos/recent.rhtml
  194. +54 −0 app/views/photos/show.rhtml
  195. +41 −0 app/views/photos/slideshow.rhtml
  196. +15 −0 app/views/polls/_edit.haml
  197. +5 −0 app/views/polls/_excerpt.haml
  198. +15 −0 app/views/polls/_new.haml
  199. +35 −0 app/views/polls/_poll_ui.haml
  200. +8 −0 app/views/polls/_polls_sidebar.haml
  201. +16 −0 app/views/posts/_blog_profile_details.rhtml
  202. +5 −0 app/views/posts/_contest.rhtml
  203. +12 −0 app/views/posts/_favorited_post.haml
  204. +6 −0 app/views/posts/_featured_posts_sidebar.haml
  205. +5 −0 app/views/posts/_most_commented_sidebar.haml
  206. +8 −0 app/views/posts/_popular_posts_sidebar.haml
  207. +10 −0 app/views/posts/_post.rhtml
  208. +27 −0 app/views/posts/_post_tools.rhtml
  209. +35 −0 app/views/posts/_send_to_friend.rhtml
  210. +63 −0 app/views/posts/edit.rhtml
  211. +31 −0 app/views/posts/featured.haml
  212. +52 −0 app/views/posts/index.rhtml
  213. +59 −0 app/views/posts/new.haml
  214. +51 −0 app/views/posts/popular.rhtml
  215. +22 −0 app/views/posts/preview.rhtml
  216. +18 −0 app/views/posts/recent.rhtml
  217. +98 −0 app/views/posts/show.rhtml
  218. +13 −0 app/views/sb_posts/_dummy_forum_post.rhtml
  219. +30 −0 app/views/sb_posts/_edit.rhtml
  220. +13 −0 app/views/sb_posts/edit.rhtml
  221. +6 −0 app/views/sb_posts/edit.rjs
  222. +61 −0 app/views/sb_posts/index.rhtml
  223. +20 −0 app/views/sb_posts/index.rxml
  224. +59 −0 app/views/sb_posts/monitored.rhtml
  225. +15 −0 app/views/sb_posts/monitored.rxml
  226. +3 −0 app/views/sb_posts/update.rjs
  227. +38 −0 app/views/sessions/new.rhtml
  228. +18 −0 app/views/shared/_admin_nav.rhtml
  229. +17 −0 app/views/shared/_bio_help.rhtml
  230. +36 −0 app/views/shared/_blog_excerpt.rhtml
  231. +39 −0 app/views/shared/_comment_form.rhtml
  232. +16 −0 app/views/shared/_featured_writer.rhtml
  233. +33 −0 app/views/shared/_footer_content.rhtml
  234. +14 −0 app/views/shared/_friendship.rhtml
  235. +21 −0 app/views/shared/_location_chooser.rhtml
  236. +18 −0 app/views/shared/_messages.rhtml
  237. +10 −0 app/views/shared/_new_clipping.rhtml
  238. +10 −0 app/views/shared/_new_photo.rhtml
  239. +10 −0 app/views/shared/_new_post.rhtml
  240. +8 −0 app/views/shared/_new_user.rhtml
  241. +12 −0 app/views/shared/_skilled.rhtml
  242. +10 −0 app/views/shared/_small_profile.rhtml
  243. +66 −0 app/views/shared/_user.rhtml
  244. +25 −0 app/views/shared/_user_menu.haml
  245. +9 −0 app/views/shared/_user_sidebar.haml
  246. +20 −0 app/views/sitemap/index.haml
  247. +28 −0 app/views/sitemap/index.rxml
  248. +7 −0 app/views/sitemap/sitemap_helper.rb
  249. +13 −0 app/views/skills/edit.rhtml
  250. +46 −0 app/views/skills/index.rhtml
  251. +12 −0 app/views/skills/new.rhtml
  252. +26 −0 app/views/skills/show.rhtml
  253. +33 −0 app/views/statistics/activities.rxml
  254. +58 −0 app/views/statistics/index.rhtml
  255. 0 app/views/subnav/_blog.haml
  256. +28 −0 app/views/tags/index.rhtml
  257. +94 −0 app/views/tags/show.rhtml
  258. +34 −0 app/views/topics/_form.rhtml
  259. +22 −0 app/views/topics/_recent_topics_sidebar.haml
  260. +10 −0 app/views/topics/edit.rhtml
  261. +2 −0 app/views/topics/index.rhtml
  262. +16 −0 app/views/topics/new.rhtml
  263. +179 −0 app/views/topics/show.rhtml
  264. +16 −0 app/views/topics/show.rxml
  265. +11 −0 app/views/user_notifier/activation.rhtml
  266. +8 −0 app/views/user_notifier/comment_notice.rhtml
  267. +15 −0 app/views/user_notifier/follow_up_comment_notice.rhtml
  268. +8 −0 app/views/user_notifier/forgot_username.rhtml
  269. +8 −0 app/views/user_notifier/friendship_request.rhtml
  270. +14 −0 app/views/user_notifier/new_forum_post_notice.rhtml
  271. +108 −0 app/views/user_notifier/post_recommendation.rhtml
  272. +7 −0 app/views/user_notifier/reset_password.rhtml
  273. +14 −0 app/views/user_notifier/signup_invitation.rhtml
  274. +16 −0 app/views/user_notifier/signup_notification.rhtml
  275. +8 −0 app/views/users/_offering.rhtml
  276. +41 −0 app/views/users/_profile_details.rhtml
  277. +34 −0 app/views/users/_profile_nav.rhtml
  278. +28 −0 app/views/users/_search_options.rhtml
  279. +3 −0 app/views/users/_skill.rhtml
  280. +8 −0 app/views/users/_welcome_steps.rhtml
  281. +73 −0 app/views/users/dashboard.haml
  282. +151 −0 app/views/users/edit.rhtml
  283. +57 −0 app/views/users/edit_account.rhtml
  284. +30 −0 app/views/users/forgot_password.rhtml
  285. +30 −0 app/views/users/forgot_username.rhtml
  286. +23 −0 app/views/users/index.rhtml
  287. +35 −0 app/views/users/invite.rhtml
  288. +56 −0 app/views/users/new.rhtml
  289. +121 −0 app/views/users/show.rhtml
  290. +10 −0 app/views/users/signup_completed.rhtml
  291. +44 −0 app/views/users/statistics.rhtml
  292. +80 −0 app/views/users/welcome_about.rhtml
  293. 0 app/views/users/welcome_complete.rhtml
  294. +19 −0 app/views/users/welcome_invite.rhtml
  295. +29 −0 app/views/users/welcome_photo.rhtml
  296. +46 −0 app/views/users/welcome_stylesheet.rhtml
  297. +6 −0 app/views/votes/create.rjs
  298. BIN assets/charts/charts.swf
  299. BIN assets/charts/charts_library/arno.swf
  300. BIN assets/charts/charts_library/arst.swf
Sorry, we could not display the entire diff because too many files (1,784) changed.
View
1 .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
84 README
@@ -0,0 +1,84 @@
+COMMUNITY ENGINE
+================
+Requires RAILS VERSION 2.0.2 AND the engines plugin (http://rails-engines.org/news/2007/12/11/engines-2-0-ish/)
+
+REQUIREMENTS (if you don't do these things, the plugin won't work)
+==================================================================
+
+STEPS:
+1. rails site_name
+2. Commit to svn
+3. Install engines plugin
+4. Checkout community engine plugin into plugins directory
+5. set svn props external on community_engine dir
+ - svn propset svn:externals "community_engine https://feedmarker.textdriven.com/svn/missingmethod/plugins/community_engine/trunk" vendor/plugins/
+
+6. Delete default application.rb and application_helper
+7. Add s3.yml and amazon_s3.yml to root config directory
+8. Create your database and modify your config/database.yml appropriately
+9. Delete public/index.html (if you haven't already)
+10. Modify your environment files
+11. Generate community engine migrations: script/generate plugin_migration
+12. Generate sql_sessions migration: script/generate sql_session_store mysql
+13. rake db:migrate
+
+Modify your environment file
+Here's a sample:
+============================
+
+RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
+require File.join(File.dirname(__FILE__), 'boot')
+require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')
+
+Rails::Initializer.run do |config|
+ #resource_hacks required here to ensure routes like /:login_slug work
+ #if removed, defaults to /users/:login_slug
+ config.plugins = ["engines", "community_engine", 'resource_hacks', 'white_list', '*']
+ config.plugin_paths += ["#{RAILS_ROOT}/vendor/plugins/community_engine/engine_plugins"]
+end
+
+# Include your application configuration below
+require "#{RAILS_ROOT}/vendor/plugins/community_engine/engine_config/community_engine.rb"
+
+
+Modify your routes.rb, adding this after any of your own existing routes:
+==============================
+ map.from_plugin :community_engine
+
+
+Modify each environment file (development.rb, production.rb, test.rb) to include something like:
+================================================================================================
+APP_URL = "http://localhost:3000"
+
+
+Create an application.yml file in RAILS_ROOT/config (OPTIONAL)
+=================================================
+The application configuration defined in this file overrides the one defined in /community_engine/engine_config/application.yml
+This is where you can change commonly used config variables, like AppConfig.community_name, etc.
+
+
+Create an amazon_s3.yml file in RAILS_ROOT/config (REQUIRED)
+=================================================
+CommunityEngine uses attachment_fu (engine_plugins/attachment_fu) for image processing
+And attachment_fu needs the s3 config in order to store images on s3. Duh. (Sample in engine_config/amazon_s3.yml)
+
+
+Create an s3.yml file in RAILS_ROOT/config (OPTIONAL)
+=================================================
+CommunityEngine includes the s3.rake tasks for backing up your site to S3. If you plan on using these, you'll need to add a file
+in RAILS_ROOT/config/s3.yml. (Sample in engine_config/s3.yml)
+
+
+
+
+Getting started
+===============
+From your app root, run:
+script/generate plugin_migration
+rake db:migrate
+
+
+Other notes
+===========
+If you have an existing application.rb, nothing will work unless you modify it to
+include the methods in community_engine's application.rb (your application.rb takes precedence)
View
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the community_engine plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the community_engine plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'CommunityEngine'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
7 about.yml
@@ -0,0 +1,7 @@
+author: Bruno Bornsztein
+email: bruno.bornsztein@gmail.com
+homepage: http://www.missingmethod.com
+summary: A social netorking engine
+description: Adds basic social networking capabilities to your existing application, including user object, blogs, photos
+license: MIT
+version: 0.0.1
View
23 app/controllers/admin_controller.rb
@@ -0,0 +1,23 @@
+class AdminController < ApplicationController
+ before_filter :admin_required
+
+ def users
+ cond = Caboose::EZ::Condition.new
+ if params['login']
+ cond.login =~ "%#{params['login']}%"
+ end
+ if params['email']
+ cond.email =~ "%#{params['email']}%"
+ end
+
+ @pages, @users = paginate :users, :per_page => 100, :order => "created_at DESC", :conditions => cond.to_sql
+ end
+
+ def activate_user
+ user = User.find(params[:id])
+ user.activate
+ flash[:notice] = "The user was activated"
+ redirect_to :action => :users
+ end
+
+end
View
82 app/controllers/ads_controller.rb
@@ -0,0 +1,82 @@
+class AdsController < ApplicationController
+ before_filter :login_required
+ before_filter :admin_required
+
+ # GET /ads
+ # GET /ads.xml
+ def index
+ @ads = Ad.find(:all)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @ads.to_xml }
+ end
+ end
+
+ # GET /ads/1
+ # GET /ads/1.xml
+ def show
+ @ad = Ad.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.xml { render :xml => @ad.to_xml }
+ end
+ end
+
+ # GET /ads/new
+ def new
+ @ad = Ad.new
+ end
+
+ # GET /ads/1;edit
+ def edit
+ @ad = Ad.find(params[:id])
+ end
+
+ # POST /ads
+ # POST /ads.xml
+ def create
+ @ad = Ad.new(params[:ad])
+
+ respond_to do |format|
+ if @ad.save
+ flash[:notice] = 'Ad was successfully created.'
+ format.html { redirect_to ad_url(@ad) }
+ format.xml { head :created, :location => ad_url(@ad) }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @ad.errors.to_xml }
+ end
+ end
+ end
+
+ # PUT /ads/1
+ # PUT /ads/1.xml
+ def update
+ @ad = Ad.find(params[:id])
+
+ respond_to do |format|
+ if @ad.update_attributes(params[:ad])
+ flash[:notice] = 'Ad was successfully updated.'
+ format.html { redirect_to ad_url(@ad) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @ad.errors.to_xml }
+ end
+ end
+ end
+
+ # DELETE /ads/1
+ # DELETE /ads/1.xml
+ def destroy
+ @ad = Ad.find(params[:id])
+ @ad.destroy
+
+ respond_to do |format|
+ format.html { redirect_to ads_url }
+ format.xml { head :ok }
+ end
+ end
+end
View
143 app/controllers/application.rb
@@ -0,0 +1,143 @@
+require 'hpricot'
+require 'open-uri'
+require 'pp'
+
+# Filters added to this controller will be run for all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+class ApplicationController < ActionController::Base
+ helper :advertising
+ include AuthenticatedSystem
+ before_filter :login_from_cookie
+
+ caches_action :site_index, :footer_content
+
+ def cache_action?(action_name)
+ !logged_in? && controller_name.eql?('application') && params[:format].blank?
+ end
+ def action_fragment_key(options)
+ url = url_for(options).split('://').last
+ url = (url =~ /^.*\/$/) ? "#{url}index" : url
+ url
+ end
+
+ if AppConfig.closed_beta_mode
+ before_filter :beta_login_required, :except => [:teaser]
+ end
+
+ def teaser
+ redirect_to home_path and return if current_user
+ render :layout => 'beta'
+ end
+
+ def rss_site_index
+ redirect_to :controller => 'application', :action => 'site_index', :format => 'rss'
+ end
+
+ def plaxo
+ render :layout => false
+ end
+
+ def site_index
+ @posts = Post.find_recent(:limit => 16)
+
+ @rss_title = "Curbly Recent Posts"
+ @rss_url = rss_url
+ respond_to do |format|
+ format.html { get_additional_homepage_data }
+ format.rss do
+ render_rss_feed_for(@posts, { :feed => {:title => "#{AppConfig.community_name} Recent Posts", :link => recent_url},
+ :item => {:title => :title, :link => :link_for_rss, :description => :post, :pub_date => :created_at}
+ })
+ end
+ end
+ end
+
+ def footer_content
+ get_recent_footer_content
+ render :partial => 'shared/footer_content' and return
+ end
+
+ def homepage_features
+ @homepage_features = HomepageFeature.find_features
+ @homepage_features.shift
+ render :partial => 'homepage_feature', :collection => @homepage_features and return
+ end
+
+ def about
+ end
+
+ def advertise
+ end
+
+ def faq
+ end
+
+ def css_help
+ end
+
+ def admin_required
+ current_user && current_user.admin? ? true : access_denied
+ end
+
+ def find_user
+ if @user = User.find(params[:user_id] || params[:id])
+ @is_current_user = (@user && @user.eql?(current_user))
+ unless logged_in? || @user.profile_public?
+ flash.now[:error] = "This user's profile is not public. You'll need to create an account and log in to access it."
+ redirect_to :controller => 'sessions', :action => 'new'
+ end
+ return @user
+ else
+ flash.now[:error] = "Please log in."
+ redirect_to :controller => 'sessions', :action => 'new'
+ return false
+ end
+ end
+
+ def require_current_user
+ @user ||= User.find(params[:user_id] || params[:id] )
+ unless admin? || (@user && (@user.eql?(current_user)))
+ redirect_to :controller => 'sessions', :action => 'new' and return false
+ end
+ return @user
+ end
+
+ def popular_tags(limit = nil, order = ' tags.name ASC', type = nil)
+ sql = "SELECT tags.id, tags.name, count(*) AS count
+ FROM taggings, tags
+ WHERE tags.id = taggings.tag_id "
+ sql += " AND taggings.taggable_type = '#{type}'" unless type.nil?
+ sql += " GROUP BY tag_id"
+ sql += " ORDER BY #{order}"
+ sql += " LIMIT #{limit}" if limit
+ Tag.find_by_sql(sql).sort{ |a,b| a.name.downcase <=> b.name.downcase}
+ end
+
+
+ def get_recent_footer_content
+ @recent_clippings = Clipping.find_recent(:limit => 10)
+ @recent_photos = Photo.find_recent(:limit => 10)
+ @recent_comments = Comment.find_recent(:limit => 13)
+ @recent_questions = Post.find(:all, :conditions => ["category_id = ?", Category.get(:questions).id], :order => 'created_at DESC', :limit => 10)
+ @popular_tags = popular_tags(30, ' count DESC')
+ end
+
+ def get_additional_homepage_data
+ @sidebar_right = true
+ @homepage_features = HomepageFeature.find_features
+ @homepage_features_data = @homepage_features.collect {|f| [f.id, f.public_filename(:large) ] }
+
+ @active_users = User.find_by_activity({:limit => 5, :require_avatar => false})
+ @featured_writers = User.find_featured
+
+ @featured_posts = Post.find_featured
+
+ @topics = Topic.find(:all, :limit => 5, :order => "replied_at DESC")
+ @question_count = Category.get_recent_count(:questions)
+ @how_to_count = Category.get_recent_count(:how_to)
+ @active_contest = Contest.get_active
+ @popular_posts = Post.find_popular({:limit => 10})
+ @popular_polls = Poll.find_popular(:limit => 8)
+ end
+
+end
View
116 app/controllers/categories_controller.rb
@@ -0,0 +1,116 @@
+class CategoriesController < ApplicationController
+ before_filter :login_required, :except => [:show, :most_viewed, :rss]
+ before_filter :admin_required, :only => [:new, :edit, :update, :create, :destroy]
+
+ # GET /categories
+ # GET /categories.xml
+ def index
+ @categories = Category.find(:all)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @categories.to_xml }
+ end
+ end
+
+ # GET /categories/1
+ # GET /categories/1.xml
+ def show
+ @category = Category.find(params[:id])
+ @sidebar_right = true
+
+ cond = Caboose::EZ::Condition.new
+ cond.category_id == @category.id
+ order = (params[:popular] ? "view_count #{params[:popular]}": "created_at DESC")
+ @pages, @posts = paginate :posts, :order => order, :conditions => cond.to_sql, :include => :tags
+
+ @popular_posts = @category.posts.find(:all, :limit => 10, :order => "view_count DESC")
+ @popular_polls = Poll.find_popular_in_category(@category)
+
+ @rss_title = "#{AppConfig.community_name}: #{@category.name} posts"
+ @rss_url = formatted_category_path(@category, :rss)
+
+ @active_users = User.find(:all,
+ :include => :posts,
+ :limit => 5,
+ :conditions => ["posts.category_id = ? AND posts.created_at > ?", @category.id, 14.days.ago],
+ :order => "users.view_count DESC"
+ )
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.rss {
+ render_rss_feed_for(@posts, {:feed => {:title => "#{AppConfig.community_name}: #{@category.name} posts", :link => category_url(@category)},
+ :item => {:title => :title, :link => :link_for_rss, :description => :post, :pub_date => :created_at} })
+ }
+ end
+ end
+
+ # GET /categories/new
+ def new
+ @category = Category.new
+ end
+
+ # GET /categories/1;edit
+ def edit
+ @category = Category.find(params[:id])
+ end
+
+ # POST /categories
+ # POST /categories.xml
+ def create
+ @category = Category.new(params[:category])
+
+ respond_to do |format|
+ if @category.save
+ flash[:notice] = 'Category was successfully created.'
+
+ format.html { redirect_to category_url(@category) }
+ format.xml do
+ headers["Location"] = category_url(@category)
+ render :nothing => true, :status => "201 Created"
+ end
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @category.errors.to_xml }
+ end
+ end
+ end
+
+ # PUT /categories/1
+ # PUT /categories/1.xml
+ def update
+ @category = Category.find(params[:id])
+
+ respond_to do |format|
+ if @category.update_attributes(params[:category])
+ format.html { redirect_to category_url(@category) }
+ format.xml { render :nothing => true }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @category.errors.to_xml }
+ end
+ end
+ end
+
+ # DELETE /categories/1
+ # DELETE /categories/1.xml
+ def destroy
+ @category = Category.find(params[:id])
+ @category.destroy
+
+ respond_to do |format|
+ format.html { redirect_to categories_url }
+ format.xml { render :nothing => true }
+ end
+ end
+
+ def show_tips
+ @category = Category.find(params[:id] )
+ render :partial => "/categories/tips", :locals => {:category => @category}
+ rescue ActiveRecord::RecordNotFound
+ render :partial => "/categories/tips", :locals => {:category => nil}
+ end
+
+
+end
View
188 app/controllers/clippings_controller.rb
@@ -0,0 +1,188 @@
+class ClippingsController < ApplicationController
+ before_filter :login_required, :only => [:new, :edit, :update, :create, :destroy, :new_clipping]
+ before_filter :find_user, :only => [:new, :edit, :index, :show]
+ before_filter :require_current_user, :only => [:new, :edit, :update, :destroy]
+ uses_tiny_mce(:options => DEFAULT_MCE_OPTONS, :only => [:show,:new_clipping])
+
+
+ def site_index
+ cond = Caboose::EZ::Condition.new
+ if params[:tag_name]
+ cond.append ['tags.name = ?', params[:tag_name]]
+ end
+ cond.append ['created_at > ?', 2.weeks.ago]
+ order = (params[:recent] ? "created_at DESC" : "clippings.favorited_count DESC")
+
+
+ @pages, @clippings = paginate(:clippings,
+ :order => order,
+ :conditions => cond.to_sql,
+ :include => :tags,
+ :per_page => 30)
+
+ @rss_title = "#{AppConfig.community_name}: #{params[:popular] ? 'Popular' : 'Recent'} Clippings"
+ @rss_url = rss_site_clippings_path
+ respond_to do |format|
+ format.html
+ format.rss {
+ render_rss_feed_for(@clippings,
+ { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'site_index') },
+ :item => {:title => :title_for_rss,
+ :description => :description_for_rss,
+ :link => :link_for_rss,
+ :pub_date => :created_at} })
+
+ }
+ end
+
+ end
+
+ # GET /clippings
+ # GET /clippings.xml
+ def index
+ @user = User.find(params[:user_id])
+
+ cond = Caboose::EZ::Condition.new
+ cond.user_id == @user.id
+ if params[:tag_name]
+ cond.append ['tags.name = ?', params[:tag_name]]
+ end
+
+ @pages, @clippings = paginate :clippings, :order => "created_at DESC", :conditions => cond.to_sql, :include => :tags
+
+ @tags = Clipping.tags_count :user_id => @user.id, :limit => 20
+ @clippings_data = @clippings.collect {|c| [c.id, c.image_url, c.description, c.url ] }
+
+ @rss_title = "#{AppConfig.community_name}: #{@user.login}'s clippings"
+ @rss_url = formatted_user_clippings_path(@user,:rss)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.js { render :inline => @clippings_data.to_json }
+ format.widget { render :template => 'clippings/widget', :layout => false }
+ format.rss {
+ render_rss_feed_for(@clippings,
+ { :feed => {:title => @rss_title, :link => url_for(:controller => 'clippings', :action => 'index', :user_id => @user) },
+ :item => {:title => :title_for_rss,
+ :description => :description_for_rss,
+ :link => :url,
+ :pub_date => :created_at} })
+
+ }
+ end
+ end
+
+ # GET /clippings/1
+ # GET /clippings/1.xml
+ def show
+ @user = User.find(params[:user_id])
+ @clipping = Clipping.find(params[:id])
+ @previous = @clipping.previous_clipping
+ @next = @clipping.next_clipping
+
+ @related = Clipping.find_related_to(@clipping)
+
+ respond_to do |format|
+ format.html # show.rhtml
+ end
+ end
+
+ def load_images_from_uri
+ uri = URI.parse(params[:uri])
+ begin
+ doc = Hpricot( open( uri ) )
+ rescue
+ render :inline => "<h1>Sorry, there was an error fetching the images from the page you requested</h1><a href='#{params[:uri]}'>Go back...</a>"
+ return
+ end
+ @page_title = (doc/"title")
+ # get the images
+ @images = []
+ (doc/"img").each do |img|
+ begin
+ if URI.parse(URI.escape(img['src'])).scheme.nil?
+ img_uri = "#{uri.scheme}://#{uri.host}/#{img['src']}"
+ else
+ img_uri = img['src']
+ end
+ @images << img_uri
+ rescue
+ nil
+ end
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def new_clipping
+ @user = current_user
+ @clipping = @user.clippings.new({:url => params[:uri], :description => params[:selection]})
+ @post = @user.posts.new_from_bookmarklet(params)
+ render :action => "new_clipping", :layout => false
+ end
+
+ # GET /clippings/new
+ def new
+ @user = User.find(params[:user_id])
+ @clipping = @user.clippings.new
+ end
+
+ # GET /clippings/1;edit
+ def edit
+ @clipping = Clipping.find(params[:id])
+ @user = User.find(params[:user_id])
+ end
+
+ # POST /clippings
+ # POST /clippings.xml
+ def create
+ @user = current_user
+ @clipping = @user.clippings.new(params[:clipping])
+ @clipping.user = @user
+
+ respond_to do |format|
+ if @clipping.save!
+ @clipping.tag_with(params[:tag_list] || '')
+ flash[:notice] = 'Clipping was successfully created.'
+ format.html {
+ unless params[:user_id]
+ redirect_to_url(@clipping.url) rescue redirect_to user_clipping_url(@user, @clipping)
+ else
+ redirect_to user_clipping_url(@user, @clipping)
+ end
+ }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ # PUT /clippings/1
+ # PUT /clippings/1.xml
+ def update
+ @user = User.find(params[:user_id])
+ @clipping = Clipping.find(params[:id])
+
+ respond_to do |format|
+ if @clipping.update_attributes(params[:clipping])
+ @clipping.tag_with(params[:tag_list] || '')
+ format.html { redirect_to user_clipping_url(@user, @clipping) }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ # DELETE /clippings/1
+ # DELETE /clippings/1.xml
+ def destroy
+ @user = User.find(params[:user_id])
+ @clipping = Clipping.find(params[:id])
+ @clipping.destroy
+
+ respond_to do |format|
+ format.html { redirect_to user_clippings_url(@user) }
+ end
+ end
+end
View
35 app/controllers/comment_sweeper.rb
@@ -0,0 +1,35 @@
+class CommentSweeper < ActionController::Caching::Sweeper
+ observe Comment
+
+ def after_create(comment)
+ expire_cache_for(comment)
+ end
+
+ # If our sweeper detects that a comment was updated call this
+ def after_update(comment)
+ expire_cache_for(comment)
+ end
+
+ # If our sweeper detects that a comment was deleted call this
+ def after_destroy(comment)
+ expire_cache_for(comment)
+ end
+
+ private
+ def expire_cache_for(record)
+ # Expire the footer content
+ expire_action :controller => 'application', :action => 'footer_content'
+
+ if record.commentable_type.eql?('Post')
+ expire_action :controller => 'posts', :action => 'show', :id => record.commentable , :user_id => record.commentable.user
+
+ if Post.find_recent(:limit => 16).include?(record.commentable)
+ # Expire the home page
+ expire_action :controller => 'application', :action => 'site_index'
+ # Expire the category pages
+ expire_action :controller => 'categories', :action => 'show', :id => record.commentable.category
+ end
+ end
+
+ end
+end
View
138 app/controllers/comments_controller.rb
@@ -0,0 +1,138 @@
+class CommentsController < ApplicationController
+ before_filter :login_required, :except => [:index]
+ uses_tiny_mce(:options => SIMPLE_MCE_OPTIONS, :only => [:index])
+
+ cache_sweeper :comment_sweeper, :only => [:create, :destroy]
+
+ def show
+ @comment = Comment.find(params[:id])
+ render :text => @comment.inspect
+ end
+
+ def index
+ @commentable = Inflector.constantize(Inflector.camelize(params[:commentable_type])).find(params[:commentable_id])
+
+ unless logged_in? || @commentable.owner.profile_public?
+ flash.now[:error] = "This user's profile is not public. You'll need to create an account and log in to access it."
+ redirect_to :controller => 'sessions', :action => 'new' and return
+ end
+
+ if @commentable
+ @comments_count = @commentable.comments.count
+ @pages = Paginator.new self, @comments_count, 10, (params[:page] || 1)
+ @comments = @commentable.comments.find(:all,
+ :limit => @pages.items_per_page,
+ :offset => @pages.current.offset,
+ :order => 'created_at DESC'
+ )
+
+ unless @comments.empty?
+ @title = @comments.first.commentable_name
+ @rss_title = "#{AppConfig.community_name}: Comments - #{@title}"
+ @rss_url = formatted_comments_path(Inflector.underscore(@commentable.class),@commentable.id, :rss)
+
+ respond_to do |format|
+ format.html {
+ @user = @comments.first.recipient
+ render :action => 'index' and return
+ }
+ format.rss {
+ @rss_title = "#{AppConfig.community_name}: #{Inflector.underscore(@commentable.class).capitalize} Comments - #{@title}"
+ @rss_url = comments_url(Inflector.underscore(@commentable.class), @commentable.to_param)
+ render_rss_feed_for(@comments,
+ { :feed => {:title => @title},
+ :item => {:title => :title_for_rss,
+ :description => :comment,
+ :link => :generate_commentable_url,
+ :pub_date => :created_at} }) and return
+
+ }
+ end
+ end
+ end
+
+
+ respond_to do |format|
+ format.html {
+ flash[:notice] = "Sorry, we couldn't find any comments for that #{Inflector.constantize(Inflector.camelize(params[:commentable_type]))}"
+ redirect_to :controller => 'application', :action => 'site_index'
+ }
+ format.rss {
+ @rss_title = "#{AppConfig.community_name}: #{Inflector.underscore(@commentable.class).capitalize} Comments - #{@title}"
+ @rss_url = comments_url(Inflector.underscore(@commentable.class), @commentable.to_param)
+ render_rss_feed_for(@comments,
+ { :feed => {:title => @title},
+ :item => {:title => :title_for_rss,
+ :description => :comment,
+ :link => :generate_commentable_url,
+ :pub_date => :created_at} }) and return
+
+ }
+ end
+ end
+
+ def new
+ @commentable = Inflector.constantize(Inflector.camelize(params[:commentable_type])).find(params[:commentable_id])
+ redirect_to "#{url_for(:controller => Inflector.underscore(params[:commentable_type]).pluralize, :action => 'show', :id => params[:commentable_id], :user_id => @commentable.owner.to_param)}#comments"
+ end
+
+
+ def create
+ @commentable = Inflector.constantize(Inflector.camelize(params[:commentable_type])).find(params[:commentable_id])
+ @comment = Comment.new(params[:comment])
+ @comment.recipient = @commentable.owner
+ @comment.user_id = current_user.id
+
+ respond_to do |format|
+ if @comment.save
+ @commentable.add_comment @comment
+ UserNotifier.deliver_comment_notice(@comment) if should_receive_notification(@comment)
+ deliver_comment_notice_to_previous_commenters(@comment)
+
+ flash.now[:notice] = 'Comment was successfully created.'
+ format.html { redirect_to :controller => Inflector.underscore(params[:commentable_type]).pluralize, :action => 'show', :id => params[:commentable_id], :user_id => @comment.recipient.id }
+ format.js {
+ render :partial => 'comments/comment', :locals => {:comment => @comment, :highlighted => true}
+ }
+ else
+ flash.now[:error] = "Your comment couldn't be saved. #{@comment.errors.full_messages.join(", ")}"
+ format.html { redirect_to :controller => Inflector.underscore(params[:commentable_type]).pluralize, :action => 'show', :id => params[:commentable_id] }
+ format.js{
+ render :inline => flash[:error], :status => 500
+ }
+ end
+ end
+ end
+
+ def destroy
+ @comment = Comment.find(params[:id])
+ if @comment.user.eql?(current_user) or current_user.admin?
+ @comment.destroy
+ flash.now[:notice] = "The comment was deleted."
+ else
+ flash.now[:error] = "Comment could not be deleted."
+ end
+ respond_to do |format|
+ format.html { redirect_to users_url }
+ format.js {
+ render :inline => flash[:error], :status => 500 if flash[:error]
+ render :nothing => true if flash[:notice]
+ }
+ end
+ end
+
+ protected
+
+ def deliver_comment_notice_to_previous_commenters(comment)
+ comment.previous_commenters_to_notify.each do |user|
+ UserNotifier.deliver_follow_up_comment_notice(user, comment)
+ end
+ end
+
+ def should_receive_notification(comment)
+ return false if comment.recipient.eql?(@comment.user)
+ return false unless comment.recipient.notify_comments?
+ true
+ end
+
+end
View
86 app/controllers/contests_controller.rb
@@ -0,0 +1,86 @@
+class ContestsController < ApplicationController
+ before_filter :login_required, :except => [:show]
+ before_filter :admin_required, :except => [:show]
+
+ uses_tiny_mce(:options => DEFAULT_MCE_OPTONS, :only => [:new, :edit ])
+ # GET /contests
+ # GET /contests.xml
+ def index
+ @contests = Contest.find(:all)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @contests.to_xml }
+ end
+ end
+
+ # GET /contests/1
+ # GET /contests/1.xml
+ def show
+ @contest = Contest.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.xml { render :xml => @contest.to_xml }
+ end
+ end
+
+ # GET /contests/new
+ def new
+ @contest = Contest.new
+ end
+
+ # GET /contests/1;edit
+ def edit
+ @contest = Contest.find(params[:id])
+ end
+
+ # POST /contests
+ # POST /contests.xml
+ def create
+ @contest = Contest.new(params[:contest])
+
+ respond_to do |format|
+ if @contest.save
+ flash[:notice] = 'Contest was successfully created.'
+
+ format.html { redirect_to contest_url(@contest) }
+ format.xml do
+ headers["Location"] = contest_url(@contest)
+ render :nothing => true, :status => "201 Created"
+ end
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @contest.errors.to_xml }
+ end
+ end
+ end
+
+ # PUT /contests/1
+ # PUT /contests/1.xml
+ def update
+ @contest = Contest.find(params[:id])
+
+ respond_to do |format|
+ if @contest.update_attributes(params[:contest])
+ format.html { redirect_to contest_url(@contest) }
+ format.xml { render :nothing => true }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @contest.errors.to_xml }
+ end
+ end
+ end
+
+ # DELETE /contests/1
+ # DELETE /contests/1.xml
+ def destroy
+ @contest = Contest.find(params[:id])
+ @contest.destroy
+
+ respond_to do |format|
+ format.html { redirect_to contests_url }
+ format.xml { render :nothing => true }
+ end
+ end
+end
View
68 app/controllers/events_controller.rb
@@ -0,0 +1,68 @@
+class EventsController < ApplicationController
+ uses_tiny_mce(:options => DEFAULT_MCE_OPTONS, :only => [:new, :edit, :create, :update ])
+
+ before_filter :admin_required, :except => [:index, :show]
+
+ def show
+ @event = Event.find(params[:id])
+ end
+
+ def index
+ @is_admin_user = (current_user && current_user.admin?)
+ @pages, @events = paginate :events, :order => "start_time DESC"
+ end
+
+ def new
+ @event = Event.new(params[:event])
+ end
+
+ def edit
+ @event = Event.find(params[:id])
+ end
+
+ def create
+ @event = Event.new(params[:event])
+ @event.user = current_user
+
+ respond_to do |format|
+ if @event.save
+ flash[:notice] = 'Event was successfully created.'
+
+ format.html { redirect_to events_path }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ def update
+ @event = Event.find(params[:id])
+ if params[:metro_area_id]
+ @event.metro_area = MetroArea.find(params[:metro_area_id])
+ else
+ @event.metro_area = nil
+ end
+
+
+ respond_to do |format|
+ if @event.update_attributes(params[:event])
+ format.html { redirect_to events_path }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ # DELETE /homepage_features/1
+ # DELETE /homepage_features/1.xml
+ def destroy
+ @event = Event.find(params[:id])
+ @event.destroy
+
+ respond_to do |format|
+ format.html { redirect_to events_path }
+ end
+ end
+
+
+end
View
29 app/controllers/favorite_sweeper.rb
@@ -0,0 +1,29 @@
+class FavoriteSweeper < ActionController::Caching::Sweeper
+ observe Favorite
+
+ def after_create(favorite)
+ expire_cache_for(favorite)
+ end
+
+ def after_destroy(favorite)
+ expire_cache_for(favorite)
+ end
+
+ private
+ def expire_cache_for(record)
+ #the favorite is for a post
+ if record.favoritable_type.eql?('Post')
+ # expire the show page
+ expire_page :controller => 'posts', :action => 'show', :id => record.favoritable, :user_id => record.favoritable.user
+
+ if Post.find_recent(:limit => 16).include?(record.favoritable)
+ # Expire the home page
+ expire_action :controller => 'application', :action => 'site_index'
+
+ # Expire the category page for this post
+ expire_action :controller => 'categories', :action => 'show', :id => record.favoritable.category
+ end
+ end
+
+ end
+end
View
40 app/controllers/favorites_controller.rb
@@ -0,0 +1,40 @@
+class FavoritesController < ApplicationController
+ before_filter :login_required, :only => [:destroy]
+ before_filter :find_user, :only => [:show, :index]
+
+ cache_sweeper :favorite_sweeper, :only => [:create, :destroy]
+
+ def create
+ @favoritable = params[:favoritable_type].classify.constantize.find(params[:favoritable_id])
+ @favorite = Favorite.new(:ip_address => request.remote_ip, :favoritable => @favoritable )
+ @favorite.user = current_user || nil
+ @favorite.save
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def destroy
+ @favorite = current_user.favorites.find(params[:id])
+ @favorite.destroy
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def show
+ @favorite = @user.favorites.find(params[:id])
+ end
+
+ def index
+ cond = Caboose::EZ::Condition.new
+ cond.append ['user_id = ?', @user.id]
+
+ @pages, @favorites = paginate :favorites, :order => "created_at DESC", :conditions => cond.to_sql
+
+ end
+
+
+end
View
68 app/controllers/forums_controller.rb
@@ -0,0 +1,68 @@
+class ForumsController < ApplicationController
+ before_filter :login_required, :except => [:index, :show]
+ before_filter :find_or_initialize_forum
+ helper :application
+ uses_tiny_mce :options => DEFAULT_MCE_OPTONS
+
+ def index
+ @forums = Forum.find(:all, :order => "position")
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @forums.to_xml }
+ end
+ end
+
+ def show
+ respond_to do |format|
+ format.html do
+ # keep track of when we last viewed this forum for activity indicators
+ (session[:forums] ||= {})[@forum.id] = Time.now.utc if logged_in?
+ @topic_pages, @topics = paginate(:topics, :per_page => 25, :conditions => ['forum_id = ?', params[:id]], :include => :replied_by_user, :order => 'sticky desc, replied_at desc')
+ end
+
+ format.xml do
+ render :xml => @forum.to_xml
+ end
+ end
+ end
+
+ # new renders new.rhtml
+
+ def create
+ @forum.attributes = params[:forum]
+ @forum.save!
+ @forum.tag_with(params[:tag_list] || '')
+ respond_to do |format|
+ format.html { redirect_to forums_path }
+ format.xml { head :created, :location => formatted_forum_url(:id => @forum, :format => :xml) }
+ end
+ end
+
+ def update
+ @forum.attributes = params[:forum]
+ @forum.save!
+ @forum.tag_with(params[:tag_list] || '')
+ respond_to do |format|
+ format.html { redirect_to forums_path }
+ format.xml { head 200 }
+ end
+ end
+
+ def destroy
+ @forum.destroy
+ respond_to do |format|
+ format.html { redirect_to forums_path }
+ format.xml { head 200 }
+ end
+ end
+
+ protected
+ def find_or_initialize_forum
+ @forum = params[:id] ? Forum.find(params[:id]) : Forum.new
+ end
+
+ #overide in your app
+ def authorized?
+ current_user.admin?
+ end
+end
View
143 app/controllers/friendships_controller.rb
@@ -0,0 +1,143 @@
+class FriendshipsController < ApplicationController
+ before_filter :login_required, :except => [:accepted, :index]
+ before_filter :find_user, :only => [:accepted, :pending, :denied]
+ before_filter :require_current_user, :only => [:accept, :deny, :pending, :destroy]
+
+ def index
+ @body_class = 'friendships-browser'
+
+ @user = (params[:id] ||params[:user_id]) ? User.find((params[:id] || params[:user_id] )): Friendship.find(:first, :order => "rand()").user
+ @friendships = Friendship.find(:all, :conditions => ['user_id = ? OR friend_id = ?', @user.id, @user.id], :limit => 40, :order => "rand()")
+ @users = User.find(:all, :conditions => ['users.id in (?)', @friendships.collect{|f| f.friend_id }])
+
+ respond_to do |format|
+ format.html
+ format.xml { render :action => 'index.rxml', :layout => false}
+ end
+ end
+
+ def deny
+ @user = User.find(params[:user_id])
+ @friendship = @user.friendships_not_initiated_by_me.find(params[:id])
+
+ respond_to do |format|
+ if @friendship.update_attributes(:friendship_status => FriendshipStatus[:denied]) && @friendship.reverse.update_attributes(:friendship_status => FriendshipStatus[:denied])
+ flash[:notice] = "The friendship was denied."
+ format.html { redirect_to denied_user_friendships_path(@user) }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ def accept
+ @user = User.find(params[:user_id])
+ @friendship = @user.friendships_not_initiated_by_me.find(params[:id])
+
+ respond_to do |format|
+ if @friendship.update_attributes(:friendship_status => FriendshipStatus[:accepted]) && @friendship.reverse.update_attributes(:friendship_status => FriendshipStatus[:accepted])
+ flash[:notice] = "The friendship was accepted."
+ format.html {
+ redirect_to accepted_user_friendships_path(@user)
+ }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ def denied
+ @user = User.find(params[:user_id])
+ @friendships = @user.friendships.find(:all, :conditions => ["friendship_status_id = ?", FriendshipStatus[:denied].id])
+
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+
+ def accepted
+ @user = User.find(params[:user_id])
+ @friend_count = @user.accepted_friendships.count
+ @pending_friendships_count = @user.pending_friendships.count
+
+ @pages = Paginator.new self, @friend_count, 20, params[:page]
+ @friendships = @user.friendships.find(:all,
+ :conditions => ["friendship_status_id = ?", FriendshipStatus[:accepted].id],
+ :limit => @pages.items_per_page,
+ :offset => @pages.current.offset
+ )
+
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+ def pending
+ @user = User.find(params[:user_id])
+ @friendships = @user.friendships.find(:all, :conditions => ["initiator = 0 and friendship_status_id = ?", FriendshipStatus[:pending].id])
+
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+ # GET /friendships/1
+ # GET /friendships/1.xml
+ def show
+ @friendship = Friendship.find(params[:id])
+ @user = @friendship.user
+
+ respond_to do |format|
+ format.html # show.rhtml
+ end
+ end
+
+ # GET /friendships/1;edit
+ def edit
+ @user = User.find(params[:user_id])
+ @friendship = @user.friendships_not_initiated_by_me.find(params[:id])
+ end
+
+ # POST /friendships
+ # POST /friendships.xml
+ def create
+ @user = User.find(params[:user_id])
+ @friendship = Friendship.new(:user_id => params[:user_id], :friend_id => params[:friend_id], :initiator => true )
+ @friendship.friendship_status_id = FriendshipStatus[:pending].id
+ reverse_friendship = Friendship.new(params[:friendship])
+ reverse_friendship.friendship_status_id = FriendshipStatus[:pending].id
+ reverse_friendship.user_id, reverse_friendship.friend_id = @friendship.friend_id, @friendship.user_id
+
+ respond_to do |format|
+ if @friendship.save && reverse_friendship.save
+ UserNotifier.deliver_friendship_request(@friendship) if @friendship.friend.notify_friend_requests?
+ format.html {
+ flash[:notice] = "Requested friendship with #{@friendship.friend.login}."
+ redirect_to accepted_user_friendships_path(@user)
+ }
+ format.js { render( :inline => "Requested friendship with #{@friendship.friend.login}." ) }
+ else
+ flash.now[:error] = 'Friendship could not be created'
+ @users = User.find(:all)
+ format.html { redirect_to user_friendships_path(@user) }
+ format.js { render( :inline => "Friendship request failed." ) }
+ end
+ end
+ end
+
+ # DELETE /friendships/1
+ # DELETE /friendships/1.xml
+ def destroy
+ @user = User.find(params[:user_id])
+ @friendship = Friendship.find(params[:id])
+ Friendship.transaction do
+ @friendship.destroy
+ @friendship.reverse.destroy
+ end
+ respond_to do |format|
+ format.html { redirect_to accepted_user_friendships_path(@user) }
+ end
+ end
+
+end
View
76 app/controllers/homepage_features_controller.rb
@@ -0,0 +1,76 @@
+class HomepageFeaturesController < ApplicationController
+ uses_tiny_mce(:options => DEFAULT_MCE_OPTONS, :only => [:new, :edit ])
+
+ before_filter :login_required
+ before_filter :admin_required
+ # GET /homepage_features
+ # GET /homepage_features.xml
+ def index
+ @homepage_features = HomepageFeature.find(:all, :conditions => ["parent_id IS NULL"], :order => "created_at desc")
+
+ respond_to do |format|
+ format.html # index.rhtml
+ end
+ end
+
+ # GET /homepage_features/1
+ # GET /homepage_features/1.xml
+ def show
+ @homepage_feature = HomepageFeature.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ end
+ end
+
+ # GET /homepage_features/new
+ def new
+ @homepage_feature = HomepageFeature.new
+ end
+
+ # GET /homepage_features/1;edit
+ def edit
+ @homepage_feature = HomepageFeature.find(params[:id])
+ end
+
+ # POST /homepage_features
+ # POST /homepage_features.xml
+ def create
+ @homepage_feature = HomepageFeature.new(params[:homepage_feature])
+
+ respond_to do |format|
+ if @homepage_feature.save
+ flash[:notice] = 'Homepage Feature was successfully created.'
+
+ format.html { redirect_to homepage_feature_url(@homepage_feature) }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+ # PUT /homepage_features/1
+ # PUT /homepage_features/1.xml
+ def update
+ @homepage_feature = HomepageFeature.find(params[:id])
+
+ respond_to do |format|
+ if @homepage_feature.update_attributes(params[:homepage_feature])
+ format.html { redirect_to homepage_feature_url(@homepage_feature) }
+ else
+ format.html { render :action => "edit" }
+ end
+ end
+ end
+
+ # DELETE /homepage_features/1
+ # DELETE /homepage_features/1.xml
+ def destroy
+ @homepage_feature = HomepageFeature.find(params[:id])
+ @homepage_feature.destroy
+
+ respond_to do |format|
+ format.html { redirect_to homepage_features_url }
+ end
+ end
+end
View
61 app/controllers/invitations_controller.rb
@@ -0,0 +1,61 @@
+class InvitationsController < ApplicationController
+ before_filter :require_current_user, :only => [:create, :edit, :update, :destroy]
+ # GET /invitations
+ # GET /invitations.xml
+ def index
+ @user = User.find(params[:user_id])
+ @invitations = @user.invitations
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @invitations.to_xml }
+ end
+ end
+
+ # GET /invitations/1
+ # GET /invitations/1.xml
+ def show
+ @invitation = Invitation.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.xml { render :xml => @invitation.to_xml }
+ end
+ end
+
+ # GET /invitations/new
+ def new
+ @user = User.find(params[:user_id])
+ @invitation = Invitation.new
+ end
+
+ # GET /invitations/1;edit
+ def edit
+ @invitation = Invitation.find(params[:id])
+ end
+
+ # POST /invitations
+ # POST /invitations.xml
+ def create
+ @user = User.find(params[:user_id])
+
+ @invitation = Invitation.new(params[:invitation])
+ @invitation.user = @user
+
+ respond_to do |format|
+ if @invitation.save
+ flash[:notice] = 'Invitation was successfully created.'
+ format.html {
+ unless params[:welcome]
+ redirect_to user_path(@invitation.user)
+ else
+ redirect_to welcome_complete_user_path(@invitation.user)
+ end
+ }
+ else
+ format.html { render :action => "new" }
+ end
+ end
+ end
+
+end
View
68 app/controllers/metro_areas_controller.rb
@@ -0,0 +1,68 @@
+class MetroAreasController < ApplicationController
+ before_filter :login_required
+ before_filter :admin_required
+
+ def index
+ @pages, @metro_areas = paginate :metro_areas, :order => "countries.name, metro_areas.name", :include => :country
+ end
+
+ def show
+ @metro_area = MetroArea.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.xml { render :xml => @metro_area.to_xml }
+ end
+ end
+
+ def new
+ @metro_area = MetroArea.new
+ end
+
+ def edit
+ @metro_area = MetroArea.find(params[:id])
+ end
+
+ def create
+ @metro_area = MetroArea.new(params[:metro_area])
+
+ respond_to do |format|
+ if @metro_area.save
+ flash[:notice] = 'MetroArea was successfully created.'
+
+ format.html { redirect_to metro_area_url(@metro_area) }
+ format.xml do
+ headers["Location"] = metro_area_url(@metro_area)
+ render :nothing => true, :status => "201 Created"
+ end
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @metro_area.errors.to_xml }
+ end
+ end
+ end
+
+ def update
+ @metro_area = MetroArea.find(params[:id])
+
+ respond_to do |format|
+ if @metro_area.update_attributes(params[:metro_area])
+ format.html { redirect_to metro_area_url(@metro_area) }
+ format.xml { render :nothing => true }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @metro_area.errors.to_xml }
+ end
+ end
+ end
+
+ def destroy
+ @metro_area = MetroArea.find(params[:id])
+ @metro_area.destroy
+
+ respond_to do |format|
+ format.html { redirect_to metro_areas_url }
+ format.xml { render :nothing => true }
+ end
+ end
+end
View
19 app/controllers/moderators_controller.rb
@@ -0,0 +1,19 @@
+class ModeratorsController < ApplicationController
+ before_filter :login_required
+
+ def create
+ @forum = Forum.find(params[:forum_id])
+ @user = User.find(params[:user_id])
+ @moderatorship = Moderatorship.create!(:forum => @forum, :user => @user)
+ end
+
+ def destroy
+ @moderatorship = Moderatorship.find(params[:id])
+ @moderatorship.destroy
+ end
+
+ #overide in your app
+ def authorized?
+ current_user.admin?
+ end
+end
View
20 app/controllers/monitorships_controller.rb
@@ -0,0 +1,20 @@
+class MonitorshipsController < ApplicationController
+ before_filter :login_required
+
+ def create
+ @monitorship = Monitorship.find_or_initialize_by_user_id_and_topic_id(current_user.id, params[:topic_id])
+ @monitorship.update_attribute :active, true
+ respond_to do |format|
+ format.html { redirect_to forum_topic_path(params[:forum_id], params[:topic_id]) }
+ format.js
+ end
+ end
+
+ def destroy
+ Monitorship.update_all ['active = ?', false], ['user_id = ? and topic_id = ?', current_user.id, params[:topic_id]]
+ respond_to do |format|
+ format.html { redirect_to forum_topic_path(params[:forum_id], params[:topic_id]) }
+ format.js
+ end
+ end
+end
View
107 app/controllers/offerings_controller.rb
@@ -0,0 +1,107 @@
+class OfferingsController < ApplicationController
+ before_filter :find_user, :only => [:replace]
+ before_filter :login_required
+ before_filter :require_current_user, :only => [:replace, :destroy, :edit, :update]
+
+ # GET /offerings
+ # GET /offerings.xml
+ def index
+ @offerings = Offering.find(:all)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @offerings.to_xml }
+ end
+ end
+
+ # GET /offerings/1
+ # GET /offerings/1.xml
+ def show
+ @offering = Offering.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.rhtml
+ format.xml { render :xml => @offering.to_xml }
+ end
+ end
+
+ # GET /offerings/new
+ def new
+ @offering = Offering.new
+ end
+
+ # GET /offerings/1;edit
+ def edit
+ @offering = Offering.find(params[:id])
+ end
+
+ # POST /offerings
+ # POST /offerings.xml
+ def create
+ @offering = Offering.new(params[:offering])
+
+ respond_to do |format|
+ if @offering.save
+ flash[:notice] = 'Offering was successfully created.'
+
+ format.html { redirect_to user_offering_url(@offering) }
+ format.xml do
+ headers["Location"] = user_offering_url(@offering)
+ render :nothing => true, :status => "201 Created"
+ end
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @offering.errors.to_xml }
+ end
+ end
+ end
+
+ # PUT /offerings/1
+ # PUT /offerings/1.xml
+ def update
+ @offering = Offering.find(params[:id])
+
+ respond_to do |format|
+ if @offering.update_attributes(params[:offering])
+ format.html { redirect_to user_offering_url(@offering) }
+ format.xml { render :nothing => true }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @offering.errors.to_xml }
+ end
+ end
+ end
+
+ def replace
+ @user.offerings.clear
+ params[:users_skills].compact.each do |skill_id|
+ offering = Offering.new(:skill_id => skill_id)
+ offering.user = @user
+ offering.save
+ end
+
+ respond_to do |format|
+ format.js { render :nothing => true }
+ end
+ end
+
+ # DELETE /offerings/1
+ # DELETE /offerings/1.xml
+ def destroy
+ @user = User.find(params[:user_id])
+ @offering = Offering.find(params[:id])
+ if @offering.destroy
+ flash.now[:notice] = "The service was deleted."
+ else
+ flash.now[:error] = "Service could not be deleted."
+ end
+
+ respond_to do |format|
+ format.html { redirect_to edit_user_path(@user) }
+ format.js {
+ render :inline => flash[:error], :status => 500 if flash[:error]
+ render :nothing => true if flash[:notice]
+ }
+ end
+ end
+end
View
221 app/controllers/photos_controller.rb
@@ -0,0 +1,221 @@
+require 'pp'
+require 'mime/types'
+
+class PhotosController < ApplicationController
+ before_filter :login_required, :only => [:new, :edit, :update, :destroy, :create, :manage_photos]
+ before_filter :find_user, :only => [:new, :edit, :index, :show, :slideshow]
+ before_filter :require_current_user, :only => [:new, :edit, :update, :destroy]
+ before_filter :require_fake_session, :only => [:create_multiple]
+ skip_before_filter :login_required, :only => [:create_multiple]
+ uses_tiny_mce(:options => SIMPLE_MCE_OPTIONS, :only => [:show])
+
+ def recent
+ @pages, @photos = paginate :photo, :order => "created_at DESC", :conditions => ["parent_id IS NULL"]
+ end
+
+ # GET /photos
+ # GET /photos.xml
+ def index
+ @user = User.find(params[:user_id])
+
+ cond = Caboose::EZ::Condition.new
+ cond.user_id == @user.id
+ if params[:tag_name]
+ cond.append ['tags.name = ?', params[:tag_name]]
+ end
+
+ @pages, @photos = paginate :photos, :order => "created_at DESC", :conditions => cond.to_sql, :include => :tags
+
+ @tags = Photo.tags_count :user_id => @user.id, :limit => 20
+
+ @rss_title = "#{AppConfig.community_name}: #{@user.login}'s photos"
+ @rss_url = formatted_user_photos_path(@user,:rss)
+
+ respond_to do |format|
+ format.html # index.rhtml
+ format.rss {
+ render_rss_feed_for(@photos,
+ { :feed => {:title => @rss_title, :link => url_for(:controller => 'photos', :action => 'index', :user_id => @user) },
+