Commit 24405209 authored by 神楽坂玲奈's avatar 神楽坂玲奈

4-1

git-svn-id: http://glupx.googlecode.com/svn/trunk/Reliz@59 189f022a-1064-8ae2-3e6f-c4a67275c50b
parent 87965f10
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
Themes_Dir = 'app/views/themes'
protect_from_forgery protect_from_forgery
before_filter :load_settings before_filter :load_settings
...@@ -19,36 +21,46 @@ class ApplicationController < ActionController::Base ...@@ -19,36 +21,46 @@ class ApplicationController < ActionController::Base
end end
end end
def load_locale def load_locale
p request.env['HTTP_ACCEPT_LANGUAGE'] locale = @correct_user.locale || (
#locale = @correct_user.locale || ( request_language =
# request_language = request_language && request_language['HTTP_ACCEPT_LANGUAGE'][/[^,;]+/]
#request_language && request_language['HTTP_ACCEPT_LANGUAGE'][/[^,;]+/] )
#) I18n.locale = locale if File.exist?("#{RAILS_ROOT}/config/locales/#{request_language}.yml")
#I18n.locale = locale if File.exist?("#{RAILS_ROOT}/config/locales/#{request_language}.yml")
User::Guest.name = t 'user.guest' User::Guest.name = t 'user.guest'
#IE && FF are BANNED
end end
def load_theme def load_theme
if !@correct_user.theme.blank? case #TODO: DRY
theme_path = "app/themes/#{@correct_user.theme}" when @site[:themes].has_key?(cookies[:theme])
prepend_view_path theme_path if File.directory? theme_path prepend_view_path File.join Themes_Dir, cookies[:theme]
elsif !@site.theme.blank? when @site[:themes].has_key?(@correct_user.theme)
theme_path = "app/themes/#{@site.theme}" prepend_view_path File.join Themes_Dir, @correct_user.theme
prepend_view_path theme_path if File.directory? theme_path when @site[:themes].has_key?(@site.theme)
end prepend_view_path File.join Themes_Dir, @site.theme
end
end end
def load_settings def load_settings
@site = { @site = {
:name => "Reliz", :name => "Reliz",
:theme => nil :theme => nil,
} }
def @site.method_missing(method, *args) def @site.method_missing(method, *args)
self[method]# || super self[method]# || super
end end
def @site.to_s def @site.to_s
"<a href=\"/\">#{name}</a>".html_safe "<a href=\"/\">#{name}</a>".html_safe
end end
#cache
@site[:themes] = {}
Dir.foreach(Themes_Dir) do |file|
theme_config_file = File.join Themes_Dir, file, "theme.yml"
if File.file? theme_config_file
@site[:themes][file] = YAML.load_file(theme_config_file)
end
end
p @site[:themes]
end end
def redirect_to_thc def redirect_to_thc
redirect_to("http://www.touhou.cc/bbs/"+params[:anything]+"?"+env['QUERY_STRING']) redirect_to("http://www.touhou.cc/bbs/"+params[:anything]+"?"+env['QUERY_STRING'])
end end
end end
\ No newline at end of file
...@@ -116,4 +116,17 @@ class UsersController < ApplicationController ...@@ -116,4 +116,17 @@ class UsersController < ApplicationController
format.xml { head :ok } format.xml { head :ok }
end end
end end
def theme
if params[:theme].blank?
cookies[:theme] = nil
@correct_user.update_attribute(:theme, nil)
elsif @site[:themes].has_key? params[:theme]
cookies[:theme] = params[:theme]
@correct_user.update_attribute(:theme, params[:theme])
end
respond_to do |format|
format.html { redirect_to :back }
format.xml { head :ok }
end
end
end end
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
Drop Drop
</option> </option>
</select> </select>
囧 囧 囧 囧 <% render 'layouts/themebar' %>
</td> </td>
</tr> </tr>
</table> </table>
......
<!--<script type="text/javascript">
function setstyle(styleid) {
str = unescape('styleid%3D57');
str = str.replace(/(^|&)styleid=\d+/ig, '');
str = (str != '' ? str + '&' : '') + 'styleid=' + styleid;
location.href = 'index.php?' + str;
}
</script>
<ul id="style_switch"><li><a href="###" onclick="setstyle(50)" title="緋紅" style="background: ;">緋紅</a></li><li><a href="###" onclick="setstyle(48)" title="金黃" style="background: ;">金黃</a></li><li><a href="###" onclick="setstyle(39)" title="翠绿" style="background: ;">翠绿</a></li><li><a href="###" onclick="setstyle(40)" title="炫紫" style="background: ;">炫紫</a></li><li><a href="###" onclick="setstyle(54)" title="酷黑" style="background: ;">酷黑</a></li><li><a href="###" onclick="setstyle(51)" title="銀白" style="background: ;">銀白</a></li><li><a href="###" onclick="setstyle(52)" title="深藍" style="background: ;">深藍</a></li><li><a href="###" onclick="setstyle(55)" title="亮橙" style="background: ;">亮橙</a></li><li><a href="###" onclick="setstyle(56)" title="清蓝" style="background: ;">清蓝</a></li><li class="current"><a href="###" onclick="setstyle(57)" title="夜露" style="background: ;">夜露</a></li><li><a href="###" onclick="setstyle(61)" title="圣诞" style="background: ;">圣诞</a></li><li><a href="###" onclick="setstyle(74)" title="黑色回忆" style="background: #373A3C;">黑色回忆</a></li></ul>
-->
<% unless @site.themes.empty? %>
<div id ="themebar">
<ul>
<li><%= link_to 'default', theme_path %></li>
<% @site.themes.each_pair do |name, theme| %>
<li><%= link_to name, theme_path, :theme => name %></li>
<% end %>
</ul>
</div>
<% end %>
\ No newline at end of file
...@@ -31,15 +31,7 @@ ...@@ -31,15 +31,7 @@
<div id="menu"> <div id="menu">
<%= render "layouts/navibar" %> <%= render "layouts/navibar" %>
</div> </div>
<script type="text/javascript"> <%= render 'layouts/themebar' %>
function setstyle(styleid) {
str = unescape('fromuid%3D8507%26styleid%3D57');
str = str.replace(/(^|&)styleid=\d+/ig, '');
str = (str != '' ? str + '&' : '') + 'styleid=' + styleid;
location.href = 'index.php?' + str;
}
</script>
</div> </div>
</div> </div>
......
Reliz::Application.routes.draw do Reliz::Application.routes.draw do
resources :settings resources :settings
resources :moderations resources :moderations
resources :boards resources :boards
...@@ -8,6 +8,7 @@ Reliz::Application.routes.draw do ...@@ -8,6 +8,7 @@ Reliz::Application.routes.draw do
root :to => 'boards#index' root :to => 'boards#index'
resources :users resources :users
match 'theme' => 'users#theme'
get 'login' => 'users#login' get 'login' => 'users#login'
post 'login' => 'users#login_do' post 'login' => 'users#login_do'
get 'logout' => 'users#logout' get 'logout' => 'users#logout'
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment