From: Florent Bruneau Date: Fri, 8 Oct 2010 09:22:30 +0000 (+0200) Subject: Administrators can easily switch between skins (without affecting their X-Git-Tag: xorg/1.0.1~75 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=b47cc6f09f0a001d1f00f4263d3b14b4eb4ce379;p=platal.git Administrators can easily switch between skins (without affecting their default skin), making tests with a specific skin much easier. Note: Maybe it might be a better idea to enable this feature for all users when the site is in debug mode and hide this (even for administrators) when the site is in release mode. Signed-off-by: Florent Bruneau --- diff --git a/classes/direnum.php b/classes/direnum.php index f083af9..5350f0e 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -57,6 +57,7 @@ class DirEnum const MEDALS = 'medals'; const ACCOUNTTYPES = 'accounttypes'; + const SKINS = 'skins'; static private $enumerations = array(); @@ -701,5 +702,16 @@ class DE_AccountTypes extends DirEnumeration } // }}} +// {{{ class DE_Skins +class DE_Skins extends DirEnumeration +{ + public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION; + + protected $from = 'skins'; + protected $valfield = 'name'; + protected $idfield = 'skin_tpl'; +} +// }}} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/classes/xorgpage.php b/classes/xorgpage.php index 2bc6d59..6a62620 100644 --- a/classes/xorgpage.php +++ b/classes/xorgpage.php @@ -44,6 +44,10 @@ class XorgPage extends PlPage } } $this->assign('account_types_list', $types); + + $skins = DirEnum::getOptions(DirEnum::SKINS); + asort($skins); + $this->assign('skin_list', $skins); } } diff --git a/modules/admin.php b/modules/admin.php index afe3aa3..f203d78 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -26,6 +26,7 @@ class AdminModule extends PLModule return array( 'phpinfo' => $this->make_hook('phpinfo', AUTH_MDP, 'admin'), 'get_rights' => $this->make_hook('get_rights', AUTH_COOKIE, 'admin'), + 'set_skin' => $this->make_hook('set_skin', AUTH_COOKIE, 'admin'), 'admin' => $this->make_hook('default', AUTH_MDP, 'admin'), 'admin/dead-but-active' => $this->make_hook('dead_but_active', AUTH_MDP, 'admin'), 'admin/deaths' => $this->make_hook('deaths', AUTH_MDP, 'admin'), @@ -83,6 +84,17 @@ class AdminModule extends PLModule } } + function handler_set_skin(&$page) + { + S::assert_xsrf_token(); + S::set('skin', Post::s('change_skin')); + if (!empty($_SERVER['HTTP_REFERER'])) { + http_redirect($_SERVER['HTTP_REFERER']); + } else { + pl_redirect('/'); + } + } + function handler_default(&$page) { $page->changeTpl('admin/index.tpl'); diff --git a/templates/skin/common.menu.tpl b/templates/skin/common.menu.tpl index 47165bd..58004c8 100644 --- a/templates/skin/common.menu.tpl +++ b/templates/skin/common.menu.tpl @@ -99,10 +99,24 @@ +
+ {xsrf_token_field} + +
{xsrf_token_field} -
- {foreach from=$account_types_list item=type}