]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/adminpanelaction.php
[CORE][ROUTER] Fix wrong parameter in all/:tag by XRevan86
[quix0rs-gnu-social.git] / lib / adminpanelaction.php
index 2e9261711b8464e386f06a2a6f64e8091706349e..36b697b302f27c7f6e9e5a5526a8a375368f3719 100644 (file)
@@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
  *
  * @todo Find some commonalities with SettingsAction and combine
  */
-
 class AdminPanelAction extends Action
 {
     var $success = true;
@@ -61,20 +60,23 @@ class AdminPanelAction extends Action
      *
      * @return boolean success flag
      */
-
-    function prepare($args)
+    function prepare(array $args = array())
     {
         parent::prepare($args);
 
         // User must be logged in.
 
         if (!common_logged_in()) {
+            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
             $this->clientError(_('Not logged in.'));
-            return;
         }
 
         $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 +90,20 @@ class AdminPanelAction extends Action
 
         // User must have the right to change admin settings
 
-        $user = common_current_user();
-
         if (!$user->hasRight(Right::CONFIGURESITE)) {
+            // TRANS: Client error message thrown when a user tries to change admin settings but has no access rights.
             $this->clientError(_('You cannot make changes to this site.'));
-            return;
+        }
+
+        // This panel must be enabled
+
+        $name = $this->trimmed('action');
+
+        $name = mb_substr($name, 0, -10);
+
+        if (!self::canAdmin($name)) {
+            // TRANS: Client error message throw when a certain panel's settings cannot be changed.
+            $this->clientError(_('Changes to that panel are not allowed.'), 403);
         }
 
         return true;
@@ -108,15 +119,19 @@ class AdminPanelAction extends Action
      *
      * @return void
      */
-
-    function handle($args)
+    function handle()
     {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->checkSessionToken();
             try {
                 $this->saveSettings();
 
+                // Reload settings
+
+                Config::loadSettings();
+
                 $this->success = true;
+                // TRANS: Message after successful saving of administrative settings.
                 $this->msg     = _('Settings saved.');
             } catch (Exception $e) {
                 $this->success = false;
@@ -126,6 +141,20 @@ 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
      *
@@ -133,19 +162,35 @@ class AdminPanelAction extends Action
      *
      * @return void.
      */
-
     function showContent()
     {
         $this->showForm();
     }
 
+    /**
+     * Show content block. Overrided just to add a special class
+     * to the content div to allow styling.
+     *
+     * @return nothing
+     */
+    function showContentBlock()
+    {
+        $this->elementStart('div', array('id' => 'content', 'class' => 'admin'));
+        $this->showPageTitle();
+        $this->showPageNoticeBlock();
+        $this->elementStart('div', array('id' => 'content_inner'));
+        // show the actual content (forms, lists, whatever)
+        $this->showContent();
+        $this->elementEnd('div');
+        $this->elementEnd('div');
+    }
+
     /**
      * show human-readable instructions for the page, or
      * a success/failure on save.
      *
      * @return void
      */
-
     function showPageNotice()
     {
         if ($this->msg) {
@@ -168,11 +213,10 @@ class AdminPanelAction extends Action
      *
      * @return void
      */
-
     function showForm()
     {
+        // TRANS: Client error message.
         $this->clientError(_('showForm() not implemented.'));
-        return;
     }
 
     /**
@@ -184,7 +228,6 @@ class AdminPanelAction extends Action
      *
      * @return void
      */
-
     function getInstructions()
     {
         return '';
@@ -197,10 +240,24 @@ class AdminPanelAction extends Action
      *
      * @return void
      */
-
     function saveSettings()
     {
+        // TRANS: Client error message
         $this->clientError(_('saveSettings() not implemented.'));
-        return;
+    }
+
+    static function canAdmin($name)
+    {
+        $isOK = false;
+
+        if (Event::handle('AdminPanelCheck', array($name, &$isOK))) {
+            $isOK = in_array($name, common_config('admin', 'panels'));
+        }
+
+        return $isOK;
+    }
+
+    function showProfileBlock()
+    {
     }
 }