Permalink
Browse files

Initial forum import

git-svn-id: http://rubyonbrforum.rubyforge.org/svn/forum/trunk@1 a3ed7fad-87d0-43c6-b013-f85f9751801c
  • Loading branch information...
0 parents commit da97177aa5509d93ecf2c955177a06e2e7bc59c2 mereghost committed Apr 11, 2008
Showing 1,462 changed files with 147,048 additions and 0 deletions.
@@ -0,0 +1,3 @@
+Ruby and JavaScript source are MIT/BSD licensed. Enjoy.
+
+Please do not reproduce the CSS/design exactly in other apps. Do feel free to make your own "sheet of paper" designs - it's easy and a great layout scheme.
1 README
@@ -0,0 +1 @@
+== Beast - Two's company. Three's a forum. More's a Beast.
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,16 @@
+class AggregatorController < ApplicationController
+
+ def index
+ end
+
+ def show
+ open('http://logbr.reflectivesurface.com/feed/rss/') do |http|
+ #open('http://eustaquiorangel.com/feeds/rss') do |http|
+ #open('http://www.balanceonrails.com.br/xml/rss/feed.xml') do |http|
+ response = http.read
+ rss = RSS::Parser.parse(response, false)
+ @channel= rss.channel
+ @items = rss.items
+ end
+ end
+end
@@ -0,0 +1,75 @@
+class ApplicationController < ActionController::Base
+ session :session_key => '_beast_session_id'
+
+
+ helper_method :current_user, :logged_in?, :admin?, :last_login
+ before_filter :login_by_token
+
+ protected
+
+ def login_required
+ login_by_token unless logged_in?
+ redirect_to login_path unless logged_in? && authorized?
+ end
+
+ def login_by_token
+ if !logged_in? && cookies[:login_token]
+ self.current_user=User.find_by_id_and_login_key(*cookies[:login_token].split(";"))
+ end
+ end
+
+ def authorized?; true; end
+
+ # this is used to keep track of the last time a user has been seen (reading a topic)
+ # it is used to know when topics are new or old and which should have the green
+ # activity light next to them
+ #
+ # we cheat by not calling it all the time, but rather only when a user views a topic
+ # which means it isn't truly "last seen at" but it does serve it's intended purpose
+ #
+ # this could be a filter for the entire app and keep with it's true meaning, but that
+ # would just slow things down without any forseeable benefit since we already know
+ # who is online from the user/session connection
+ def update_last_seen_at
+ User.update_all ['last_seen_at = ?', Time.now.utc], ['id = ?', current_user.id] if logged_in?
+ end
+
+ def current_user=(value)
+ if @current_user = value
+ session[:user_id] = @current_user.id
+ # need to remove the unless RAILS_ENV when figure out how
+ # to make this work with tests
+ session.model.user_id = @current_user.id unless RAILS_ENV=="test"
+ # this is used while we're logged in to know which threads are new, etc
+ session[:last_active] = @current_user.last_seen_at
+ session[:topics] = session[:forums] = {}
+ update_last_seen_at
+ end
+ end
+
+ def last_login; session[:last_active] ? session[:last_active] : Time.now.utc ; end
+
+ def current_user
+ @current_user ||= ((session[:user_id] && User.find_by_id(session[:user_id])) || 0)
+ end
+
+ def logged_in?; current_user != 0; end
+
+ def admin?
+ logged_in? and current_user.admin?
+ end
+
+ def rescue_action(exception)
+ exception.is_a?(ActiveRecord::RecordInvalid) ? render_invalid_record(exception.record) : super
+ end
+
+ def render_invalid_record(record)
+ render :action => (record.new_record? ? 'new' : 'edit')
+ end
+
+
+
+
+
+
+end
@@ -0,0 +1,102 @@
+class BlogsController < ApplicationController
+
+ before_filter :admin_only, :except => :blogosphere
+ before_filter :expire_index, :only => :blogosphere
+
+ def admin_only
+ #unless current_user && current_user != 0 && current_user.admin?
+ # redirect_to :forums_path
+ # false
+ #end
+ end
+
+ def expire_index
+ if last_cache < 30.minutes.ago
+ reset_cache
+ end
+ end
+
+ def blogosphere
+ respond_to do |wants|
+
+ wants.html do
+ find_posts unless read_fragment(:action => 'blogosphere', :part => 'posts')
+ end
+
+ wants.rss do
+ find_posts unless read_fragment(:action => 'blogosphere', :format => 'rss')
+ @headers["Content-Type"] = "text/xml; charset=utf-8"
+ render :partial => 'blogosphere_rss'
+ end
+ end
+ end
+
+ def reset_cache
+ reset
+ redirect_to blogs_path
+ end
+
+ def index
+ @blogs = Blog.find(:all, :order => 'author')
+ end
+
+ def new
+ @blog = Blog.new
+ end
+
+ def create
+ @blog = Blog.new(params[:blog])
+ @blog.save!
+ reset_cache
+ redirect_to blogs_path
+ end
+
+ def edit
+ @blog = Blog.find(params[:id])
+ end
+
+ def update
+ @blog = Blog.find(params[:id])
+ @blog.attributes = params[:blog]
+ @blog.save!
+ reset_cache
+ redirect_to blogs_path
+ end
+
+ def destroy
+ blog = Blog.find(params[:id])
+ blog.destroy if blog
+ redirect_to blogs_path
+ end
+
+ def reset
+ reset_cache
+ redirect_to blogs_path
+ end
+
+ def last_cache
+ config = Configuration.find_by_name('blogs_last_cache')
+ config ? Time.parse(config.value) : 1.month.ago # 1 month ago = expired cache
+ end
+
+protected
+
+ def set_cache_time()
+ config = Configuration.find_by_name('blogs_last_cache')
+ config = Configuration.new(:name => 'blogs_last_cache') unless config;
+ config.value = Time.now.to_s
+ config.save
+ end
+
+ def reset_cache
+ expire_fragment :action => 'blogosphere', :part => 'blogs'
+ expire_fragment :action => 'blogosphere', :part => 'posts'
+ expire_fragment :action => 'blogosphere', :format => 'rss'
+ end
+
+ def find_posts
+ @posts = Blog.find_all_posts
+ @blogs = @posts.collect {|it| it.blog}.uniq
+ set_cache_time
+ end
+end
@@ -0,0 +1,44 @@
+class ForumsController < ApplicationController
+ before_filter :login_required, :only => [:new, :create, :edit, :update, :destroy]
+ before_filter :find_forum, :except => [:index, :new, :create]
+ def index
+ @forums = Forum.find(:all, :order => "position")
+ #@last_posts=last_posts
+
+
+ end
+
+ def show
+ # 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]], :order => 'sticky desc, replied_at desc')
+ end
+
+ def new
+ @forum = Forum.new
+ end
+
+ def create
+ @forum = Forum.new(params[:forum])
+ @forum.save!
+ redirect_to forums_path
+ end
+
+ def update
+ @forum.attributes = params[:forum]
+ @forum.save!
+ redirect_to forums_path
+ end
+
+ def destroy
+ @forum.destroy
+ redirect_to forums_path
+ end
+
+ protected
+ def find_forum
+ @forum = Forum.find(params[:id])
+ end
+
+ def authorized?; admin?; end
+end
@@ -0,0 +1,2 @@
+class FrontPageController < ApplicationController
+end
@@ -0,0 +1,9 @@
+class ModeratorsController < ApplicationController
+ before_filter :login_required
+ def destroy
+ Moderatorship.delete_all ['id = ?', params[:id]]
+ redirect_to user_path(params[:user_id])
+ end
+
+ alias authorized? admin?
+end
@@ -0,0 +1,78 @@
+class PostsController < ApplicationController
+ before_filter :find_post, :except => [:index, :create]
+ before_filter :login_required, :except => [:index]
+
+ def index
+ conditions = []; params[:page] = 1 if params[:format] == 'rss'
+
+ [:user_id, :forum_id].each do |attr|
+ conditions << Post.send(:sanitize_sql, ["posts.#{attr} = ?", params[attr]]) if params[attr]
+ end
+ #nova pesquisa usando regexp do postgresql,o ~* insensitive
+ unless params[:q].blank?
+ words=params[:q].split(/\s/)
+ conds=(["posts.body ~* ?"] * words.size).join(" and ")
+ conditions << Post.send(:sanitize_sql, [ conds,*words])
+ end
+ @post_pages, @posts = paginate(:posts, :per_page => 25, :select => 'posts.*, topics.title as topic_title', :joins => 'inner join topics on posts.topic_id = topics.id',
+ :conditions => conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil, :order => 'posts.created_at desc, posts.id desc')
+
+ respond_to do |format|
+ format.html
+ format.rss { render :action => 'index.rxml', :layout => false }
+ end
+ end
+
+ def create
+ @topic = Topic.find_by_id_and_forum_id(params[:topic_id],params[:forum_id], :include => :forum)
+ @forum = @topic.forum
+ @post = @topic.posts.build(params[:post])
+ @post.user = current_user
+ @post.save!
+ #last_posts(:reload => @forum.id)
+ redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1')
+ rescue ActiveRecord::RecordInvalid
+ flash[:bad_reply] = 'Por favor, poste alguma coisa...'
+ redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => 'reply-form', :page => params[:page] || '1')
+ end
+
+ def update
+ @post.attributes = params[:post]
+ if @post.save
+ redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :anchor => @post.dom_id, :page => params[:page] || '1')
+ else
+ render(:action => "edit")
+ end
+ end
+
+ def destroy
+ find_forum
+ find_topic
+ @post.destroy
+ flash[:notice] = "Post de '#{CGI::escapeHTML @post.topic.title}' foi apagado."
+ if @topic.posts && @topic.posts.count > 0
+ redirect_to topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :page => params[:page])
+ else
+ @topic.destroy
+ redirect_to forum_path(@forum)
+ end
+ end
+
+ protected
+ def authorized?
+ action_name == 'create' || @post.editable_by?(current_user)
+ end
+
+ def find_post
+ @post = Post.find_by_id_and_topic_id_and_forum_id(params[:id], params[:topic_id], params[:forum_id]) || raise(ActiveRecord::RecordNotFound)
+ end
+
+ def find_forum
+ @forum = Forum.find(params[:forum_id])
+ end
+
+ def find_topic
+ @topic = @forum.topics.find(params[:topic_id])
+ end
+
+end
Oops, something went wrong.

0 comments on commit da97177

Please sign in to comment.