public
Description: The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.
Homepage: http://chyrp.net/
Clone URL: git://github.com/vito/chyrp.git
Click here to lend your support to: chyrp and make a donation at www.pledgie.com !
* Hide admin nav items if the user can't perform the action. [#96 
state:resolved]
* Vastly increased the flexibility of Admin area navigation items.
vito (author)
Thu Jul 10 13:57:38 -0700 2008
commit  13dbb213947fc67f7d87fee4f9bdb83be5bf6187
tree    0a641953ff3481f8d9e28f6475674898aa512148
parent  ef5ae7a0265e1689a93b839188dd51d1f16b10b0
...
5
6
7
 
 
8
9
10
...
23
24
25
 
 
26
27
28
29
30
31
 
32
33
34
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
...
85
86
87
 
88
89
90
...
95
96
97
 
98
99
100
101
102
103
104
 
 
105
106
107
108
109
110
111
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
114
115
116
 
 
 
 
117
 
 
118
119
120
...
125
126
127
128
129
130
131
 
 
 
 
 
 
 
 
132
133
134
135
136
137
138
 
 
 
 
 
 
139
140
141
142
 
143
144
145
 
 
 
 
146
147
148
...
5
6
7
8
9
10
11
12
...
25
26
27
28
29
30
31
32
33
34
 
35
36
37
38
...
43
44
45
 
 
 
 
 
 
 
 
 
 
 
 
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
124
125
126
127
128
129
130
...
135
136
137
138
139
140
141
142
143
144
 
145
146
147
148
149
150
 
 
 
 
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
 
169
170
171
172
173
174
175
176
177
178
...
183
184
185
 
 
 
 
186
187
188
189
190
191
192
193
194
195
196
197
 
 
 
198
199
200
201
202
203
204
205
206
 
207
208
209
210
211
212
213
214
215
216
217
0
@@ -5,6 +5,8 @@
0
 
0
   $action = ($_GET['action'] == "index" or !isset($_GET['action'])) ? $admin->determine_action() : $_GET['action'];
0
 
0
+  $admin->handle_redirects($action);
0
+
0
   class AdminTwig {
0
     public function __construct() {
0
       $this->twig = new Twig_Loader(MAIN_DIR."/admin/layout", (is_writable(INCLUDES_DIR."/caches") and !DEBUG) ? INCLUDES_DIR."/caches" : null);
0
@@ -23,12 +25,14 @@
0
         $trigger->filter($$main_nav, $main_nav."_pages");
0
       }
0
 
0
+      $visitor = Visitor::current();
0
+
0
       $admin->context["theme"]       = $theme;
0
       $admin->context["flash"]       = Flash::current();
0
       $admin->context["trigger"]     = $trigger;
0
       $admin->context["title"]       = camelize($action, true);
0
       $admin->context["site"]        = Config::current();
0
-      $admin->context["visitor"]     = Visitor::current();
0
+      $admin->context["visitor"]     = $visitor;
0
       $admin->context["logged_in"]   = logged_in();
0
       $admin->context["route"]       = array("action" => $action);
0
       $admin->context["hide_admin"]  = isset($_SESSION["chyrp_hide_admin"]);
0
@@ -39,18 +43,53 @@
0
       $admin->context["POST"]        = $_POST;
0
       $admin->context["GET"]         = $_GET;
0
 
0
-      $admin->context["selected"]   = array("write"    => (in_array($action, $write) or match("/^write_/", $action)) ?
0
-                                                          "selected" :
0
-                                                          "deselected",
0
-                                            "manage"   => (in_array($action, $manage) or match(array("/^manage_/", "/^edit_/", "/^delete_/"), $action)) ?
0
-                                                          "selected" :
0
-                                                          "deselected",
0
-                                            "settings" => (in_array($action, $settings) or match("/_settings$/", $action)) ?
0
-                                                          "selected" :
0
-                                                          "deselected",
0
-                                            "extend"   => (in_array($action, $extend)) ?
0
-                                                          "selected" :
0
-                                                          "deselected");
0
+      $admin->context["navigation"] = array();
0
+
0
+      $show = array("write" => array($visitor->group()->can("add_draft", "add_post", "add_page")),
0
+                    "manage" => array($visitor->group()->can("view_own_draft",
0
+                                                             "view_draft",
0
+                                                             "edit_own_draft",
0
+                                                             "edit_own_post",
0
+                                                             "edit_post",
0
+                                                             "delete_own_draft",
0
+                                                             "delete_own_post",
0
+                                                             "delete_post",
0
+                                                             "add_page",
0
+                                                             "edit_page",
0
+                                                             "delete_page",
0
+                                                             "add_user",
0
+                                                             "edit_user",
0
+                                                             "delete_user",
0
+                                                             "add_group",
0
+                                                             "edit_group",
0
+                                                             "delete_group")),
0
+                    "settings" => array($visitor->group()->can("change_settings")),
0
+                    "extend" => array($visitor->group()->can("toggle_extensions")));
0
+
0
+      foreach ($show as $name => &$arr)
0
+        $trigger->filter($arr, $name."_nav_show");
0
+
0
+      $admin->context["navigation"]["write"] = array("title" => __("Write"),
0
+                                                     "show" => in_array(true, $show["write"]),
0
+                                                     "selected" => (in_array($action, $write) or
0
+                                                                   match("/^write_/", $action)));
0
+
0
+      $admin->context["navigation"]["manage"] = array("title" => __("Manage"),
0
+                                                      "show" => in_array(true, $show["manage"]),
0
+                                                      "selected" => (in_array($action, $manage) or
0
+                                                                    match(array("/^manage_/",
0
+                                                                                "/^edit_/",
0
+                                                                                "/^delete_/",
0
+                                                                                "/^new_/"), $action)));
0
+
0
+      $admin->context["navigation"]["settings"] = array("title" => __("Settings"),
0
+                                                        "show" => in_array(true, $show["settings"]),
0
+                                                        "selected" => (in_array($action, $settings) or
0
+                                                                      match("/_settings$/", $action)));
0
+
0
+      $admin->context["navigation"]["extend"] = array("title" => __("Extend"),
0
+                                                      "show" => in_array(true, $show["extend"]),
0
+                                                      "selected" => (in_array($action, $extend)));
0
 
0
       $this->subnav_context();
0
 
0
@@ -85,6 +124,7 @@
0
       global $admin, $action;
0
 
0
       $trigger = Trigger::current();
0
+      $visitor = Visitor::current();
0
 
0
       $admin->context["subnav"] = array();
0
       $subnav =& $admin->context["subnav"];
0
@@ -95,26 +135,44 @@
0
       foreach (Config::current()->enabled_feathers as $index => $feather) {
0
         $info = Horde_Yaml::loadFile(FEATHERS_DIR."/".$feather."/info.yaml");
0
         $subnav["write"]["write_post&feather=".$feather] = array("title" => __($info["name"], $feather),
0
+                                                                   "show" => $visitor->group()->can("add_draft", "add_post"),
0
                                                                  "attributes" => ' id="list_feathers['.$feather.']"',
0
                                                                  "selected" => (isset($_GET['feather']) and $_GET['feather'] == $feather) or
0
                                                                                (!isset($_GET['feather']) and $action == "write_post" and !$index));
0
       }
0
 
0
       # Write navs
0
-      $subnav["write"]["write_page"] = array("title" => __("Page"));
0
+      $subnav["write"]["write_page"] = array("title" => __("Page"),
0
+                                             "show" => $visitor->group()->can("add_page"));
0
       $trigger->filter($subnav["write"], array("admin_write_nav", "write_nav"));
0
       $pages["write"] = array_merge(array("write_post"), array_keys($subnav["write"]));;
0
 
0
       # Manage navs
0
-      $subnav["manage"] = array("manage_posts"  => array("title" => __("Posts"), "selected" => array("edit_post", "delete_post")),
0
-                                "manage_pages"  => array("title" => __("Pages"), "selected" => array("edit_page", "delete_page")),
0
-                                "manage_users"  => array("title" => __("Users"), "selected" => array("edit_user", "delete_user")),
0
-                                "manage_groups" => array("title" => __("Groups"), "selected" => array("edit_group", "delete_group")));
0
+      $subnav["manage"] = array("manage_posts"  => array("title" => __("Posts"),
0
+                                                         "show" => (Post::any_editable() or Post::any_deletable()),
0
+                                                         "selected" => array("edit_post", "delete_post")),
0
+                                "manage_pages"  => array("title" => __("Pages"),
0
+                                                         "show" => ($visitor->group()->can("edit_page", "delete_page")),
0
+                                                         "selected" => array("edit_page", "delete_page")),
0
+                                "manage_users"  => array("title" => __("Users"),
0
+                                                         "show" => ($visitor->group()->can("add_user",
0
+                                                                                           "edit_user",
0
+                                                                                           "delete_user")),
0
+                                                         "selected" => array("edit_user", "delete_user", "new_user")),
0
+                                "manage_groups" => array("title" => __("Groups"),
0
+                                                         "show" => ($visitor->group()->can("add_group",
0
+                                                                                           "edit_group",
0
+                                                                                           "delete_group")),
0
+                                                         "selected" => array("edit_group", "delete_group", "new_group")));
0
       $trigger->filter($subnav["manage"], "manage_nav");
0
 
0
-      $subnav["manage"]["import"] = array("title" => __("Import"));
0
-      $subnav["manage"]["export"] = array("title" => __("Export"));
0
+      $subnav["manage"]["import"] = array("title" => __("Import"),
0
+                                          "show" => ($visitor->group()->can("add_post")));
0
+      $subnav["manage"]["export"] = array("title" => __("Export"),
0
+                                          "show" => ($visitor->group()->can("add_post")));
0
 
0
+      $pages["manage"][] = "new_user";
0
+      $pages["manage"][] = "new_group";
0
       foreach (array_keys($subnav["manage"]) as $manage)
0
         $pages["manage"] = array_merge($pages["manage"], array($manage,
0
                                                                preg_replace("/manage_(.+)/e",
0
@@ -125,24 +183,35 @@
0
                                                                             $manage)));
0
 
0
       # Settings navs
0
-      $subnav["settings"] = array("general_settings" => array("title" => __("General")),
0
-                                  "content_settings" => array("title" => __("Content")),
0
-                                  "user_settings"    => array("title" => __("Users")),
0
-                                  "route_settings"   => array("title" => __("Routes")));
0
+      $subnav["settings"] = array("general_settings" => array("title" => __("General"),
0
+                                                              "show" => $visitor->group()->can("change_settings")),
0
+                                  "content_settings" => array("title" => __("Content"),
0
+                                                              "show" => $visitor->group()->can("change_settings")),
0
+                                  "user_settings"    => array("title" => __("Users"),
0
+                                                              "show" => $visitor->group()->can("change_settings")),
0
+                                  "route_settings"   => array("title" => __("Routes"),
0
+                                                              "show" => $visitor->group()->can("change_settings")));
0
       $trigger->filter($subnav["settings"], "settings_nav");
0
       $pages["settings"] = array_keys($subnav["settings"]);
0
 
0
       # Extend navs
0
-      $subnav["extend"] = array("modules"  => array("title" => __("Modules")),
0
-                                "feathers" => array("title" => __("Feathers")),
0
-                                "themes"   => array("title" => __("Themes")));
0
+      $subnav["extend"] = array("modules"  => array("title" => __("Modules"),
0
+                                                    "show" => $visitor->group()->can("toggle_extensions")),
0
+                                "feathers" => array("title" => __("Feathers"),
0
+                                                    "show" => $visitor->group()->can("toggle_extensions")),
0
+                                "themes"   => array("title" => __("Themes"),
0
+                                                    "show" => $visitor->group()->can("toggle_extensions")));
0
       $trigger->filter($subnav["extend"], "extend_nav");
0
       $pages["extend"] = array_keys($subnav["extend"]);
0
 
0
-      foreach (array("write", "manage", "settings", "extend") as $main_nav)
0
+      foreach (array_keys($subnav) as $main_nav)
0
         foreach ($trigger->filter($pages[$main_nav], $main_nav."_nav_pages") as $extend)
0
           $subnav[$extend] =& $subnav[$main_nav];
0
 
0
+      foreach ($subnav as $main_nav => &$sub_nav)
0
+        foreach ($sub_nav as &$nav)
0
+          $nav["show"] = (!isset($nav["show"]) or $nav["show"]);
0
+
0
       $trigger->filter($subnav, "admin_subnav");
0
     }
0
   }
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
30
31
32
...
43
44
45
 
46
 
47
48
49
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
21
22
23
24
25
...
36
37
38
39
40
41
42
43
44
0
@@ -15,18 +15,11 @@ ${ trigger.call("admin_head") }
0
       <div class="column">
0
         <ul id="navigation">
0
 {% block navigation %}
0
-{% if visitor.group.can("add_draft", "add_post") %}
0
-          <li class="first $selected.write"><a href="{% admin "write_post" %}">${ "Write" | translate }</a></li>
0
-{% endif %}
0
-{% if visitor.group.can("view_own_draft", "view_draft", "edit_own_draft", "edit_own_post", "edit_post", "delete_own_draft", "delete_own_post", "delete_post") %}
0
-          <li class="second $selected.manage"><a href="{% admin "manage_posts" %}">${ "Manage" | translate }</a></li>
0
-{% endif %}
0
-{% if visitor.group.can("change_settings") %}
0
-          <li class="third $selected.settings"><a href="{% admin "general_settings" %}">${ "Settings" | translate }</a></li>
0
-{% endif %}
0
-{% if visitor.group.can("toggle_extensions") %}
0
-          <li class="fourth $selected.extend"><a href="{% admin "modules" %}">${ "Extend" | translate }</a></li>
0
-{% endif %}
0
+{% for action, nav in navigation | items %}
0
+          {% if nav.show %}
0
+          <li class="$action{% if nav.selected %} selected{% endif %}"$nav.attributes><a href="{% admin action %}">$nav.title</a></li>
0
+          {% endif %}
0
+{% endfor %}
0
 {% endblock %}
0
         </ul>
0
         <h1>$site.name</h1>
0
@@ -43,7 +36,9 @@ ${ trigger.call("admin_head") }
0
 {% block subnav %}
0
 {% if subnav[route.action] %}
0
 {% for action, nav in subnav[route.action] | items %}
0
+      {% if nav.show %}
0
       <li${ route.action | selected(nav.selected, action) }$nav.attributes><a href="{% admin action %}">$nav.title</a></li>
0
+      {% endif %}
0
 {% endfor %}
0
 {% endif %}
0
 {% endblock %}
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@
0
       <form class="detail" action="index.php" method="get" accept-charset="utf-8">
0
         <fieldset>
0
           <input type="hidden" name="action" value="manage_users" />
0
-          {% if visitor.group.can("edit_user") %}
0
+          {% if visitor.group.can("add_user") %}
0
           <a href="{% admin "new_user" %}" class="button yay right">
0
             <img src="images/icons/add.png" alt="add" /> ${ "New User" | translate }
0
           </a>
...
75
76
77
78
79
80
81
 
 
 
 
82
83
84
...
75
76
77
 
 
 
 
78
79
80
81
82
83
84
0
@@ -75,10 +75,10 @@ a:visited {
0
 #header #navigation li a:hover {
0
   opacity: 1;
0
 }
0
-#header #navigation li.first a  { border-color: #ef4646; }
0
-#header #navigation li.second a { border-color: #e19a2c; }
0
-#header #navigation li.third a  { border-color: #16d907; }
0
-#header #navigation li.fourth a { border-color: #0096ff; }
0
+#header #navigation li.write a  { border-color: #ef4646; }
0
+#header #navigation li.manage a { border-color: #e19a2c; }
0
+#header #navigation li.settings a  { border-color: #16d907; }
0
+#header #navigation li.extend a { border-color: #0096ff; }
0
 
0
 #welcome {
0
   background: #dfdfdf url('images/welcome.gif') repeat-x;
...
1689
1690
1691
1692
 
1693
1694
1695
1696
1697
 
 
 
 
1698
1699
1700
1701
 
 
 
 
 
 
 
 
 
1702
1703
1704
1705
 
 
 
1706
1707
1708
1709
 
 
 
1710
1711
1712
1713
 
 
 
 
 
 
 
 
 
 
1714
1715
1716
1717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1718
1719
1720
1721
 
 
 
 
1722
1723
 
 
 
1724
1725
1726
...
1689
1690
1691
 
1692
1693
1694
 
 
 
1695
1696
1697
1698
1699
 
 
 
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
 
 
 
1710
1711
1712
1713
 
 
 
1714
1715
1716
1717
 
 
 
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
 
 
 
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
 
 
 
1744
1745
1746
1747
1748
 
1749
1750
1751
1752
1753
1754
0
@@ -1689,38 +1689,66 @@
0
      * Function: determine_action
0
      * Determines through simple logic which page should be shown as the default when browsing to /admin/.
0
      */
0
-    public function determine_action() {
0
+    public function determine_action($action = null) {
0
       $visitor = Visitor::current();
0
 
0
-      # "Write > Post", if they can add posts or drafts.
0
-      if ($visitor->group()->can("add_post") or $visitor->group()->can("add_draft"))
0
-        return "write_post";
0
+      if (!isset($action) or $action == "write") {
0
+        # "Write > Post", if they can add posts or drafts.
0
+        if ($visitor->group()->can("add_post") or $visitor->group()->can("add_draft"))
0
+          return "write_post";
0
 
0
-      # "Write > Page", if they can add pages.
0
-      if ($visitor->group()->can("add_page"))
0
-        return "write_page";
0
+        # "Write > Page", if they can add pages.
0
+        if ($visitor->group()->can("add_page"))
0
+          return "write_page";
0
+      }
0
+
0
+      if (!isset($action) or $action == "manage") {
0
+        # "Manage > Posts", if they can manage any posts.
0
+        if (Post::any_editable() or Post::any_deletable())
0
+          return "manage_posts";
0
 
0
-      # "Manage > Posts", if they can manage any posts.
0
-      if (Post::any_editable() or Post::any_deletable())
0
-        return "manage_posts";
0
+        # "Manage > Pages", if they can manage pages.
0
+        if ($visitor->group()->can("edit_page") or $visitor->group()->can("delete_page"))
0
+          return "manage_pages";
0
 
0
-      # "Manage > Pages", if they can manage pages.
0
-      if ($visitor->group()->can("edit_page") or $visitor->group()->can("delete_page"))
0
-        return "manage_pages";
0
+        # "Manage > Users", if they can manage users.
0
+        if ($visitor->group()->can("edit_user") or $visitor->group()->can("delete_user"))
0
+          return "manage_users";
0
 
0
-      # "Manage > Users", if they can manage users.
0
-      if ($visitor->group()->can("edit_user") or $visitor->group()->can("delete_user"))
0
-        return "manage_users";
0
+        # "Manage > Groups", if they can manage groups.
0
+        if ($visitor->group()->can("edit_group") or $visitor->group()->can("delete_group"))
0
+          return "manage_groups";
0
+      }
0
+
0
+      if (!isset($action) or $action == "settings") {
0
+        # "General Settings", if they can configure the installation.
0
+        if ($visitor->group()->can("change_settings"))
0
+          return "general_settings";
0
+      }
0
 
0
-      # "Manage > Groups", if they can manage groups.
0
-      if ($visitor->group()->can("edit_group") or $visitor->group()->can("delete_group"))
0
-        return "manage_groups";
0
+      if (!isset($action) or $action == "extend") {
0
+        # "Modules", if they can configure the installation.
0
+        if ($visitor->group()->can("toggle_extensions"))
0
+          return "modules";
0
+      }
0
+
0
+      $extended = $action;
0
+      Trigger::current()->filter($extended, "determine_action");
0
+      if ($extended != $action)
0
+        return $extended;
0
+
0
+      if (!isset($action))
0
+        show_403(__("Access Denied"), __("You do not have sufficient privileges to access this area."));
0
+    }
0
 
0
-      # "Settings", if they can configure the installation.
0
-      if ($visitor->group()->can("change_settings"))
0
-        return "settings";
0
+    public function handle_redirects($action) {
0
+      $redirectable = array("write", "manage", "settings", "extend");
0
+      Trigger::current()->filter($redirectable, "admin_redirectables");
0
+      if (!in_array($action, $redirectable)) return;
0
 
0
-      show_403(__("Access Denied"), __("You do not have sufficient privileges to access this area."));
0
+      $redirect = $this->determine_action($action);
0
+      if (!empty($redirect))
0
+        redirect("/admin/?action=".$redirect);
0
     }
0
 
0
     /**
...
298
299
300
301
 
302
303
 
304
305
306
307
308
309
 
310
311
312
...
298
299
300
 
301
302
303
304
305
306
307
308
309
310
311
312
313
314
0
@@ -298,15 +298,17 @@
0
                      array($user->login, $config->name, $new_password)));
0
 
0
       if ($sent)
0
-        return Flash::warning(_f("An e-mail has been sent to your e-mail address that contains a new password. Once you have logged in with it, feel free to change it at <a href=\"%s\">User Controls</a>.",
0
+        return Flash::notice(_f("An e-mail has been sent to your e-mail address that contains a new password. Once you have logged in, you can change it at <a href=\"%s\">User Controls</a>.",
0
                                  array(url("controls/"))));
0
 
0
+      # Set their password back to what it was originally.
0
       $user->update($user->login,
0
                     $user->password,
0
                     $user->full_name,
0
                     $user->email,
0
                     $user->website,
0
                     $user->group_id);
0
+
0
       Flash::warning(__("E-Mail could not be sent. Password change cancelled."));
0
     }
0
   }
...
259
260
261
262
 
263
264
265
266
267
268
 
269
270
271
...
259
260
261
 
262
263
264
265
266
267
 
268
269
270
271
0
@@ -259,13 +259,13 @@
0
         if (in_array($string, $uncountable))
0
           break;
0
 
0
-        $replaced = preg_replace($key, $val, $string);
0
+        $replaced = preg_replace($key, $val, $string, 1);
0
 
0
         if ($replaced != $string)
0
           break;
0
       }
0
 
0
-      if ($replaced == $string and !in_array($string, $uncountable))
0
+      if ($replaced == $string and !in_array($string, $uncountable) and substr($string, -1) == "s")
0
         return substr($string, 0, -1);
0
       else
0
         return $replaced;
...
141
142
143
144
 
145
146
147
...
299
300
301
302
303
 
 
 
 
 
 
304
305
306
...
352
353
354
 
 
 
 
 
 
355
356
357
...
364
365
366
367
368
 
 
 
 
 
369
370
371
...
757
758
759
 
 
 
 
 
 
 
 
 
 
 
 
760
...
141
142
143
 
144
145
146
147
...
299
300
301
 
 
302
303
304
305
306
307
308
309
310
...
356
357
358
359
360
361
362
363
364
365
366
367
...
374
375
376
 
 
377
378
379
380
381
382
383
384
...
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
0
@@ -141,7 +141,7 @@
0
     }
0
 
0
     static function admin_manage_spam() {
0
-      if (!Comment::any_editable() and !Comment::any_deletable())
0
+      if (!Visitor::current()->group()->can("edit_comment", "delete_comment", true))
0
         show_403(__("Access Denied"), __("You do not have sufficient privileges to manage any comments.", "comments"));
0
 
0
       global $admin;
0
@@ -299,8 +299,12 @@
0
       if (!Comment::any_editable() and !Comment::any_deletable())
0
         return $navs;
0
 
0
-      $navs["manage_comments"] = array("title" => __("Comments", "comments"), "selected" => array("edit_comment", "delete_comment"));
0
-      $navs["manage_spam"]     = array("title" => __("Spam", "comments"));
0
+      $navs["manage_comments"] = array("title" => __("Comments", "comments"),
0
+                                       "selected" => array("edit_comment", "delete_comment"));
0
+
0
+      if (Visitor::current()->group()->can("edit_comment", "delete_comment"))
0
+        $navs["manage_spam"]     = array("title" => __("Spam", "comments"));
0
+
0
       return $navs;
0
     }
0
 
0
@@ -352,6 +356,12 @@
0
         $params[":query"] = "%".$search."%";
0
       }
0
 
0
+      $visitor = Visitor::current();
0
+      if (!$visitor->group()->can("edit_comment", "delete_comment", true)) {
0
+        $where[] = "__comments.user_id = :user_id";
0
+        $params[":user_id"] = $visitor->id;
0
+      }
0
+
0
       $admin->context["comments"] = new Paginator(Comment::find(array("placeholders" => true, "where" => $where, "params" => $params)), 25);
0
     }
0
 
0
@@ -364,8 +374,11 @@
0
       $comments = array_keys($_POST['comment']);
0
 
0
       if (isset($_POST['delete'])) {
0
-        foreach ($comments as $comment)
0
-          Comment::delete($comment);
0
+        foreach ($comments as $comment) {
0
+          $comment = new Comment($comment);
0
+          if ($comment->deletable())
0
+            Comment::delete($comment);
0
+        }
0
 
0
         Flash::notice(__("Selected comments deleted.", "comments"));
0
       }
0
@@ -757,4 +770,16 @@
0
 
0
       return $atom;
0
     }
0
+
0
+    public function manage_nav_show($possibilities) {
0
+      $possibilities[] = (Comment::any_editable() or Comment::any_deletable());
0
+      return $possibilities;
0
+    }
0
+
0
+    public function determine_action($action) {
0
+      if ($action != "manage") return;
0
+
0
+      if (Comment::any_editable() or Comment::any_deletable())
0
+        return "manage_comments";
0
+    }
0
   }
...
32
33
34
 
35
36
37
...
42
43
44
 
45
46
47
...
32
33
34
35
36
37
38
...
43
44
45
46
47
48
49
0
@@ -32,6 +32,7 @@
0
               <label for="author_url">${ "Author Website" | translate }</label>
0
               <input class="text" type="text" name="author_url" value="${ comment.author_url | escape }" id="author_url" />
0
             </p>
0
+{% if visitor.group.can("edit_comment") %}
0
             <p>
0
               <label for="status">${ "Status" | translate }</label>
0
               <select name="status" id="status">
0
@@ -42,6 +43,7 @@
0
                 <option value="trackback"${ comment.status | option_selected("trackback") }>${ "Trackback" | translate }</option>
0
               </select>
0
             </p>
0
+{% endif %}
0
             <p>
0
               <label for="created_at">${ "Timestamp" | translate }</label>
0
               <input class="text" type="text" name="created_at" value="${ comment.created_at | strftime }" id="created_at" />
...
21
22
23
 
24
25
26
...
36
37
38
 
39
40
41
...
82
83
84
 
85
86
87
...
98
99
100
 
101
102
103
...
21
22
23
24
25
26
27
...
37
38
39
40
41
42
43
...
84
85
86
87
88
89
90
...
101
102
103
104
105
106
107
0
@@ -21,6 +21,7 @@
0
       </form>
0
       <br />
0
       <form action="{% admin "bulk_comments" %}" method="post">
0
+{% if visitor.group.can("edit_comment", "delete_comment") %}
0
         <div class="controls right">
0
           <h4>${ "With selected:" | translate("comments") }</h4>
0
           <button class="lite" name="deny">
0
@@ -36,6 +37,7 @@
0
             <img src="images/icons/delete.png" alt="delete" /> ${ "delete" | translate("comments") }
0
           </button>
0
         </div>
0
+{% endif %}
0
         <h2>${ "Last 25 Comments" | translate("comments") }</h2>
0
         <table border="0" cellspacing="0" cellpadding="0" class="wide">
0
           <thead>
0
@@ -82,6 +84,7 @@
0
           {% endfor %}
0
           </tbody>
0
         </table>
0
+{% if visitor.group.can("edit_comment", "delete_comment") %}
0
         <br />
0
         <div class="controls">
0
           <h4>${ "With selected:" | translate("comments") }</h4>
0
@@ -98,6 +101,7 @@
0
             <img src="images/icons/delete.png" alt="delete" /> ${ "delete" | translate("comments") }
0
           </button>
0
         </div>
0
+{% endif %}
0
       </form>
0
       <br />
0
       $comments.next_link
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
     <li id="comment_$comment.id">
0
 {% if comment.status == "denied" %}
0
-      <em>${ "Your comment is awaiting moderation." | translate }</em>
0
+      <span class="waiting">${ "Your comment is awaiting moderation." | translate }</span>
0
 {% endif %}
0
       <blockquote>
0
         $comment.body
...
8
9
10
11
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
17
18
 
 
 
19
20
21
...
8
9
10
 
 
 
 
 
 
11
12
13
14
15
16
17
18
19
20
21
22
23
 
24
25
26
27
28
29
0
@@ -8,14 +8,22 @@
0
   <input type="hidden" name="email" value="$visitor.email" id="email" />
0
   <input type="hidden" name="url" value="$visitor.website" id="url" />
0
 {% else %}
0
-  <label for="author">${ "Your Name" | translate }</label>
0
-  <input type="text" name="author" value="" id="author" /><br />
0
-  <label for="email">${ "Your E-Mail" | translate }</label>
0
-  <input type="text" name="email" value="" id="email" /><br />
0
-  <label for="url">${ "Your Website" | translate }</label>
0
-  <input type="text" name="url" value="" id="url" /><br />
0
+  <p>
0
+    <label for="author">${ "Your Name" | translate }</label>
0
+    <input type="text" name="author" value="" id="author" />
0
+  </p>
0
+  <p>
0
+    <label for="email">${ "Your E-Mail" | translate }</label>
0
+    <input type="text" name="email" value="" id="email" />
0
+  </p>
0
+  <p>
0
+    <label for="url">${ "Your Website" | translate }</label>
0
+    <input type="text" name="url" value="" id="url" />
0
+  </p>
0
 {% endif %}
0
-  <textarea name="body" rows="8" cols="40" class="wide"></textarea>
0
+  <p>
0
+    <textarea name="body" rows="8" cols="40" class="wide"></textarea>
0
+  </p>
0
 
0
   <input type="hidden" name="post_id" value="$post.id" id="post_id" />
0
   <button type="submit">${ "Speak" | translate }</button>
...
1
2
3
4
5
6
7
...
1
2
3
 
4
5
6
0
@@ -1,7 +1,6 @@
0
 {% extends "layouts/default.twig" %}
0
 {% block content %}
0
   <h2>${ "Controls" | translate }</h2>
0
-  <br />
0
   <form action="{% url "update_self/" %}" method="post">
0
     <p>
0
       <label for="full_name">${ "Full Name" | translate }</label>
...
1
2
3
4
5
6
7
...
1
2
3
 
4
5
6
0
@@ -1,7 +1,6 @@
0
 {% extends "layouts/default.twig" %}
0
 {% block content %}
0
   <h2>${ "Log In" | translate }</h2>
0
-  <br />
0
   <form action="{% url "login/" %}" method="post">
0
     <p>
0
       <label for="login">${ "Username" | translate }</label>
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
16
17
18
...
1
2
3
 
4
 
 
 
 
 
 
5
6
7
 
8
9
10
11
0
@@ -1,18 +1,11 @@
0
 {% extends "layouts/default.twig" %}
0
 {% block content %}
0
   <h2>${ "Lost Password" | translate }</h2>
0
-  <br />
0
   <form action="{% url "lost_password/" %}" method="post">
0
-    {% if invalid_user %}
0
-    <p>${ "You have specified a user that does not exist." | translate }</p>
0
-    {% endif %}
0
-    {% if sent %}
0
-    <p>${ "E-mail sent!" | translate }</p>
0
-    {% endif %}
0
     <p class="lost_pass">${ "Please enter your username below and we will e-mail you a new password for your account." | translate }</p>
0
     <p>
0
       <label for="login">${ "Username" | translate }</label>
0
-      <input type="login" name="login" value="" id="login" />
0
+      <input type="text" name="login" value="" id="login" />
0
     </p>
0
 
0
     <p><button name="submit" type="submit" id="submit">${ "Submit" | translate }</button></p>
...
1
2
3
4
5
6
7
...
1
2
3
 
4
5
6
0
@@ -1,7 +1,6 @@
0
 {% extends "layouts/default.twig" %}
0
 {% block content %}
0
   <h2>${ "Register" | translate }</h2>
0
-  <br />
0
   <form action="{% url "registration/" %}" method="post">
0
     <p>
0
       <label for="login">${ "Username" | translate }</label>
...
369
370
371
 
 
 
 
372
373
374
...
609
610
611
612
 
 
613
614
615
...
369
370
371
372
373
374
375
376
377
378
...
613
614
615
 
616
617
618
619
620
0
@@ -369,6 +369,10 @@ ol.comments ol li {
0
   list-style-type: decimal;
0
 }
0
 
0
+#add_comment {
0
+  margin-top: 3em;
0
+}
0
+
0
 div.post {
0
   margin: 0 0 3em;
0
   word-wrap: break-word;
0
@@ -609,7 +613,8 @@ span.pages {
0
   font-weight: bold;
0
   padding: 0 0.3em;
0
 }
0
-span.who {
0
+span.who,
0
+span.waiting {
0
   background-color: #e2e2e2;
0
   font-weight: bold;
0
   display: block;

Comments