Reduced User#is_guest?, User#is_admin?, User#is_mod? callsmaster
authorNguyễn Thái Ngọc Duy <[email protected]>
Mon, 28 Aug 2006 13:25:49 +0000 (28 20:25 +0700)
committerNguyễn Thái Ngọc Duy <[email protected]>
Mon, 28 Aug 2006 13:25:49 +0000 (28 20:25 +0700)
app/helpers/forum_helper.rb
app/views/forum/index.rhtml
app/views/group/edit.rhtml
app/views/layouts/admin.rhtml
app/views/layouts/application.rhtml
app/views/topic/view.rhtml
app/views/user_profile/index.rhtml

index 0ca0b70..cf41afc 100644 (file)
@@ -1,6 +1,7 @@
 module ForumHelper
   def topic_info(topic)
     cu = current_user
+    is_guest = cu.is_guest?
     icon_text = 'Normal icon'
     item_status = ''
     icon_type = 'icon'
@@ -21,7 +22,7 @@ module ForumHelper
     end
 
     subject_new_posts = ''
-    if !cu.is_guest? and topic.last_post > cu.last_visit and topic.moved_to.nil?
+    if !is_guest and topic.last_post > cu.last_visit and topic.moved_to.nil?
       icon_text += ' ' + 'New icon'
       item_status += ' inew'
       icon_type = 'icon inew'
@@ -29,7 +30,7 @@ module ForumHelper
       subject_new_posts = '<span class="newtext">[&nbsp;'+link_to('New posts', {:controller => 'topic', :action => 'view', :id => topic.id, :new_posts => true}, {:title => 'New posts info'})+'&nbsp;]</span>'
     end
 
-    if !cu.is_guest? and Settings.show_dot == true
+    if !is_guest and Settings.show_dot == true
       subject = (topic.posts.find_by_poster_id(cu.id) != nil ? '<strong>&middot;</strong>&nbsp;' : '&nbsp;&nbsp;') + subject
     end
 
index 1be0dec..b63eb03 100644 (file)
@@ -1,5 +1,6 @@
 <%
   cu = current_user
+  is_guest = cu.is_guest?
   content_for :head_links do
 -%>
                        <ul class="conr">
@@ -10,7 +11,7 @@
   end
 
   content_for :foot_links do
-    if cu.is_guest?
+    if is_guest
       if User.guest.group.g_search
 -%>
                        <dl id="searchlinks" class="conl">
@@ -76,7 +77,7 @@
     # if we have o, we draw it now, as forum is "the next current forum"
     # o may be null in the first iteration
     if o
-      if !cu.is_guest? && o.last_post && cu.last_visit && o.last_post > cu.last_visit
+      if !is_guest && o.last_post && cu.last_visit && o.last_post > cu.last_visit
         item_status = 'inew'
         icon_text = 'New icon'
         icon_type = 'icon new'
index 5f290d1..9f0f218 100644 (file)
@@ -1,3 +1,8 @@
+<%
+is_guest = @group.is_guest?
+is_mod = @group.is_mod?
+is_admin = @group.is_admin?
+-%>
        <div class="blockform">
                <h2><span>Group settings</span></h2>
                <div class="box">
@@ -22,7 +27,7 @@
                                                                                <span>This title will override any rank users in this group have attained. Leave blank to use default title or rank.</span>
                                                                        </td>
                                                                </tr>
-<% unless @group.is_admin? -%>
+<% unless is_admin -%>
                                                                <tr>
                                                                        <th scope="row">Read board</th>
                                                                        <td>
@@ -44,7 +49,7 @@
                                                                                <span>Allow users in this group to post new topics.</span>
                                                                        </td>
                                                                </tr>
-<% unless @group.is_guest? -%>
+<% unless is_guest -%>
                                                                <tr>
                                                                        <th scope="row">Edit posts</th>
                                                                        <td>
@@ -87,7 +92,7 @@
                                                                                <span>Allow users in this group to freetext search for users in the user list.</span>
                                                                        </td>
                                                                </tr>
-<% unless @group.is_guest? -%>
+<% unless is_guest -%>
                                                                <tr>
                                                                        <th scope="row">Edit subjects interval</th>
                                                                        <td>
 <% end -%>
 <% end -%>
                                                        </table>
-<% if @group.is_mod? -%>
+<% if is_mod -%>
                                                        <p class="warntext">Please note that in order for a user in this group to have moderator abilities, he/she must be assigned to moderate one or more forums. This is done via the user administration page of the user's profile.</p>
 <% end -%>
                                                </div>
index 3fb287b..41c9e2a 100644 (file)
@@ -1,5 +1,6 @@
 <%
 cu = current_user
+is_admin = cu.is_admin?
 content_for :header do
 -%>
 <link rel="stylesheet" type="text/css" href="/style/imports/base_admin.css" />
@@ -29,7 +30,7 @@ captions = {
   'maintenance' => 'Maintenance',
   'reports' => 'Reports'
 }
-if cu.is_admin?
+if is_admin
   items = [ 'index', 'categories', 'forums', 'users', 'groups', 'options', 'permissions', 'censoring', 'ranks', 'bans', 'prune', 'maintenance', 'reports']
 else
   if Settings.mod_ban_users == true
@@ -43,7 +44,7 @@ inside_layout 'application' do
 -%>
 <div id="adminconsole" class="block2col">
        <div id="adminmenu" class="blockmenu">
-               <h2><span><%= cu.is_admin? ? 'Administrator' : 'Moderator' %> menu</span></h2>
+               <h2><span><%= is_admin ? 'Administrator' : 'Moderator' %> menu</span></h2>
                <div class="box">
                        <div class="inbox">
                                <ul>
index 3bcbb64..ccaaba7 100644 (file)
@@ -1,6 +1,7 @@
 <%
 cu = current_user
 can_moderate = cu.can_moderate?
+is_guest = cu.is_guest?
 -%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
@@ -30,7 +31,7 @@ can_moderate = cu.can_moderate?
 <% if Settings.rules -%>
                        <li id="navrules"><%= link_to "Rules", :controller => "user", :action => "list" %></li>
 <% end -%>
-<% if cu.is_guest? -%>
+<% if is_guest -%>
 <%   if User.guest.group.g_search -%>
                        <li id="navsearch"><%= link_to "Search", :controller => "search" %></li>
 <%   end -%>
@@ -50,7 +51,7 @@ can_moderate = cu.can_moderate?
 <% end -%>
                        </ul>
                </div>
-<% if !cu.is_guest? -%>
+<% if !is_guest -%>
                <div id="brdwelcome" class="inbox">
                        <ul class="conl">
                                <li>Logged in as <strong><%=h cu.username %></strong></li>
index 18071d2..b92c0eb 100644 (file)
@@ -2,6 +2,7 @@
   cu = current_user
   can_moderate_forum = cu.can_moderate_forum? @topic.forum
   can_reply = @topic.can_reply? cu
+  is_guest = cu.is_guest?
   if can_moderate_forum
     content_for :foot_links do
 -%>
@@ -55,9 +56,9 @@ for oid in [email protected]
                                        <dd>Posts: <%= o.poster_user.num_posts %></dd>
 <% end -%>
                                        <dd>
-<% if !cu.is_guest? and o.poster_user.email_setting == false -%>
+<% if !is_guest and o.poster_user.email_setting == false -%>
                                        <a href="mailto:<%= o.poster_user.email -%>">Email</a>
-<% elsif o.poster_user.email_setting == true and !cu.is_guest? -%>
+<% elsif o.poster_user.email_setting == true and !is_guest -%>
                                        <a href="<%= url_for :controller => 'user', :action => 'email', :id => o.poster_id %>">Email</a>
 <% end -%>
 <% if o.poster_user.url -%>
@@ -93,7 +94,7 @@ for oid in [email protected]
                        </div>
                        <div class="postfootright">
                                <ul>
-<% if !cu.is_guest? -%>
+<% if !is_guest -%>
                                        <li class="postreport"><%= link_to "Report", :action => 'report_post', :id => o.id %></li>
 <% end -%>
 <% if @topic.closed == false -%>
index 6a3f6b4..87217c7 100644 (file)
@@ -1,5 +1,6 @@
 <%
 cu = current_user
+is_admin = cu.is_admin?
 can_moderate = cu.can_moderate?
 -%>
        <div class="blockform">
@@ -11,12 +12,12 @@ can_moderate = cu.can_moderate?
                                                <legend>Enter your username and password</legend>
                                                <div class="infldset">
                                                        <input type="hidden" name="form_sent" value="1" />
-<% if cu.is_admin? and Settings.mod_rename_users == true -%>
+<% if is_admin and Settings.mod_rename_users == true -%>
                                                        <input type="hidden" name="old_username" value="<%=h @user.username %>).'" /><label><strong>Username</strong><br /><input type="text" name="req_username" value="<%=h @user.username %>" size="25" maxlength="25" /><br /></label>
 <% else -%>
                                                        <p>Username: <%=h @user.username %></p>
 <% end -%>
-<% if cu.id == @user.id or cu.is_admin? or (@user.group.id > Settings.group_ids[:pun_mod] and Settings.mod_change_passwords == true) -%>
+<% if cu.id == @user.id or is_admin or (@user.group.id > Settings.group_ids[:pun_mod] and Settings.mod_change_passwords == true) -%>
                                                        <p><a href="<%= url_for :action => 'change_password', :id => @user.id %>">Change password</a></p>
 <% end -%>
                                                </div>
@@ -59,7 +60,7 @@ can_moderate = cu.can_moderate?
 <% end %>
                                                        </p>
                                                        <p>Last post: <%= @user.last_post %></p>
-<% if cu.is_admin? -%>
+<% if is_admin -%>
                                                        <label>Posts<br /><input type="text" name="num_posts" value="<%= @user.num_posts %>" size="8" maxlength="8" /><br /></label><p><a href="<%= url_for :controller => 'search', :action => 'user_posts', :id => @user.id %>">Show posts</a></p>
 <% else -%>
                                                        <p>Posts: <%= @user.num_posts %> - <a href="<%= url_for :controller => 'search', :action => 'user_posts', :id => @user.id %>">Show posts</a></p>