]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/adminpanelaction.php
Merge commit 'refs/merge-requests/120' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / lib / adminpanelaction.php
index 2e9261711b8464e386f06a2a6f64e8091706349e..a6981ac6117d703128a9f9a03ff06dfe36e55499 100644 (file)
@@ -70,11 +70,15 @@ class AdminPanelAction extends Action
 
         if (!common_logged_in()) {
             $this->clientError(_('Not logged in.'));
-            return;
+            return false;
         }
 
         $user = common_current_user();
 
+        // ...because they're logged in
+
+        assert(!empty($user));
+
         // It must be a "real" login, not saved cookie login
 
         if (!common_is_real_login()) {
@@ -88,11 +92,20 @@ class AdminPanelAction extends Action
 
         // User must have the right to change admin settings
 
-        $user = common_current_user();
-
         if (!$user->hasRight(Right::CONFIGURESITE)) {
             $this->clientError(_('You cannot make changes to this site.'));
-            return;
+            return false;
+        }
+
+        // This panel must be enabled
+
+        $name = $this->trimmed('action');
+
+        $name = mb_substr($name, 0, -10);
+
+        if (!in_array($name, common_config('admin', 'panels'))) {
+            $this->clientError(_('Changes to that panel are not allowed.'), 403);
+            return false;
         }
 
         return true;
@@ -116,6 +129,10 @@ class AdminPanelAction extends Action
             try {
                 $this->saveSettings();
 
+                // Reload settings
+
+                Config::loadSettings();
+
                 $this->success = true;
                 $this->msg     = _('Settings saved.');
             } catch (Exception $e) {
@@ -126,6 +143,21 @@ class AdminPanelAction extends Action
         $this->showPage();
     }
 
+    /**
+     * Show tabset for this page
+     *
+     * Uses the AdminPanelNav widget
+     *
+     * @return void
+     * @see AdminPanelNav
+     */
+
+    function showLocalNav()
+    {
+        $nav = new AdminPanelNav($this);
+        $nav->show();
+    }
+
     /**
      * Show the content section of the page
      *
@@ -203,4 +235,105 @@ class AdminPanelAction extends Action
         $this->clientError(_('saveSettings() not implemented.'));
         return;
     }
+
+    /**
+     * Delete a design setting
+     *
+     * // XXX: Maybe this should go in Design? --Z
+     *
+     * @return mixed $result false if something didn't work
+     */
+
+    function deleteSetting($section, $setting)
+    {
+        $config = new Config();
+
+        $config->section = $section;
+        $config->setting = $setting;
+
+        if ($config->find(true)) {
+            $result = $config->delete();
+            if (!$result) {
+                common_log_db_error($config, 'DELETE', __FILE__);
+                $this->clientError(_("Unable to delete design setting."));
+                return null;
+            }
+        }
+
+        return $result;
+    }
+}
+
+/**
+ * Menu for public group of actions
+ *
+ * @category Output
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @author   Sarven Capadisli <csarven@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ *
+ * @see      Widget
+ */
+
+class AdminPanelNav extends Widget
+{
+    var $action = null;
+
+    /**
+     * Construction
+     *
+     * @param Action $action current action, used for output
+     */
+
+    function __construct($action=null)
+    {
+        parent::__construct($action);
+        $this->action = $action;
+    }
+
+    /**
+     * Show the menu
+     *
+     * @return void
+     */
+
+    function show()
+    {
+        $action_name = $this->action->trimmed('action');
+
+        $this->action->elementStart('ul', array('class' => 'nav'));
+
+        if (Event::handle('StartAdminPanelNav', array($this))) {
+
+            if ($this->canAdmin('site')) {
+                $this->out->menuItem(common_local_url('siteadminpanel'), _('Site'),
+                                     _('Basic site configuration'), $action_name == 'siteadminpanel', 'nav_site_admin_panel');
+            }
+
+            if ($this->canAdmin('design')) {
+                $this->out->menuItem(common_local_url('designadminpanel'), _('Design'),
+                                     _('Design configuration'), $action_name == 'designadminpanel', 'nav_design_admin_panel');
+            }
+
+            if ($this->canAdmin('user')) {
+                $this->out->menuItem(common_local_url('useradminpanel'), _('User'),
+                                     _('Paths configuration'), $action_name == 'useradminpanel', 'nav_design_admin_panel');
+            }
+
+            if ($this->canAdmin('paths')) {
+                $this->out->menuItem(common_local_url('pathsadminpanel'), _('Paths'),
+                                     _('Paths configuration'), $action_name == 'pathsadminpanel', 'nav_design_admin_panel');
+            }
+
+            Event::handle('EndAdminPanelNav', array($this));
+        }
+        $this->action->elementEnd('ul');
+    }
+
+    function canAdmin($name)
+    {
+        return in_array($name, common_config('admin', 'panels'));
+    }
 }