123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class AdminPanelAction extends Action
- {
- var $success = true;
- var $msg = null;
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
-
- if (!common_logged_in()) {
-
- $this->clientError(_('Not logged in.'));
- }
- $user = common_current_user();
-
- assert(!empty($user));
-
- if (!common_is_real_login()) {
-
-
- common_set_returnto($this->selfUrl());
- if (Event::handle('RedirectToLogin', array($this, $user))) {
- common_redirect(common_local_url('login'), 303);
- }
- }
-
- if (!$user->hasRight(Right::CONFIGURESITE)) {
-
- $this->clientError(_('You cannot make changes to this site.'));
- }
-
- $name = $this->trimmed('action');
- $name = mb_substr($name, 0, -10);
- if (!self::canAdmin($name)) {
-
- $this->clientError(_('Changes to that panel are not allowed.'), 403);
- }
- return true;
- }
-
- function handle()
- {
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->checkSessionToken();
- try {
- $this->saveSettings();
-
- Config::loadSettings();
- $this->success = true;
-
- $this->msg = _('Settings saved.');
- } catch (Exception $e) {
- $this->success = false;
- $this->msg = $e->getMessage();
- }
- }
- $this->showPage();
- }
-
- function showLocalNav()
- {
- $nav = new AdminPanelNav($this);
- $nav->show();
- }
-
- function showContent()
- {
- $this->showForm();
- }
-
- function showContentBlock()
- {
- $this->elementStart('div', array('id' => 'content', 'class' => 'admin'));
- $this->showPageTitle();
- $this->showPageNoticeBlock();
- $this->elementStart('div', array('id' => 'content_inner'));
-
- $this->showContent();
- $this->elementEnd('div');
- $this->elementEnd('div');
- }
-
- function showPageNotice()
- {
- if ($this->msg) {
- $this->element('div', ($this->success) ? 'success' : 'error',
- $this->msg);
- } else {
- $inst = $this->getInstructions();
- $output = common_markup_to_html($inst);
- $this->elementStart('div', 'instructions');
- $this->raw($output);
- $this->elementEnd('div');
- }
- }
-
- function showForm()
- {
-
- $this->clientError(_('showForm() not implemented.'));
- }
-
- function getInstructions()
- {
- return '';
- }
-
- function saveSettings()
- {
-
- $this->clientError(_('saveSettings() not implemented.'));
- }
- 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()
- {
- }
- }
|