From eaa8c4897d60fb6e8b76ea5ec1e84c0a0b815927 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 22 Oct 2013 00:17:06 +0200 Subject: [PATCH] Closed #39 --- config.ini | 2 +- public_html/media/css/user-view.css | 6 ++++ src/Controllers/CommentController.php | 2 +- src/Controllers/PostController.php | 2 +- src/Controllers/UserController.php | 40 +++++++++++++++++++++++++-- src/Models/Model_User.php | 17 ++++++++++++ src/Views/user-settings.phtml | 37 +++++++++++++++++++++++++ src/Views/user-view.phtml | 14 +++++++++- 8 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 src/Views/user-settings.phtml diff --git a/config.ini b/config.ini index 2f5c2d8d..73c14075 100644 --- a/config.ini +++ b/config.ini @@ -17,7 +17,7 @@ postsPerPage=20 thumbWidth=150 thumbHeight=150 thumbStyle=outside -endlessScrolling=1 +endlessScrollingDefault=1 maxSearchTokens=4 [comments] diff --git a/public_html/media/css/user-view.css b/public_html/media/css/user-view.css index d0b786fb..b95748c9 100644 --- a/public_html/media/css/user-view.css +++ b/public_html/media/css/user-view.css @@ -40,14 +40,20 @@ padding: 0; } +form.settings label.left, +form.delete label.left, form.edit label.left { width: 9em; } +form.settings .alert, +form.delete .alert, form.edit .alert { margin: 1em 0; } +form.settings input, +form.delete input, form.edit select, form.edit input { width: 16em; diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 28ba813f..69049a28 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -12,7 +12,7 @@ class CommentController $this->context->stylesheets []= 'comment-list.css'; $this->context->stylesheets []= 'comment-small.css'; $this->context->subTitle = 'comments'; - if ($this->config->browsing->endlessScrolling) + if ($this->config->user->hasEnabledEndlessScrolling()) $this->context->scripts []= 'paginator-endless.js'; $page = intval($page); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 5ae34e35..1f653327 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -60,7 +60,7 @@ class PostController $this->context->stylesheets []= 'post-small.css'; $this->context->stylesheets []= 'post-list.css'; $this->context->stylesheets []= 'paginator.css'; - if ($this->config->browsing->endlessScrolling) + if ($this->context->user->hasEnabledEndlessScrolling()) $this->context->scripts []= 'paginator-endless.js'; //redirect requests in form of /posts/?query=... to canonical address diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 9bf8fb0a..8ee8a948 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -53,7 +53,7 @@ class UserController { $this->context->stylesheets []= 'user-list.css'; $this->context->stylesheets []= 'paginator.css'; - if ($this->config->browsing->endlessScrolling) + if ($this->context->user->hasEnabledEndlessScrolling()) $this->context->scripts []= 'paginator-endless.js'; $page = intval($page); @@ -217,6 +217,42 @@ class UserController + /** + * @route /user/{name}/settings + * @validate name [^\/]+ + */ + public function settingsAction($name) + { + $user = Model_User::locate($name); + PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user)); + + $this->context->handleExceptions = true; + $this->context->transport->user = $user; + $this->context->transport->tab = 'settings'; + $this->context->viewName = 'user-view'; + $this->context->stylesheets []= 'user-view.css'; + $this->context->subTitle = $name; + + if (InputHelper::get('submit')) + { + $suppliedSafety = InputHelper::get('safety'); + if (!is_array($suppliedSafety)) + $suppliedSafety = []; + foreach (PostSafety::getAll() as $safety) + $user->enableSafety($safety, in_array($safety, $suppliedSafety)); + + $user->enableEndlessScrolling(InputHelper::get('endless-scrolling')); + + R::store($user); + $this->context->transport->user = $user; + if ($this->context->user->id == $user->id) + $this->context->user = $user; + $this->context->transport->success = true; + } + } + + + /** * @route /user/{name}/edit * @validate name [^\/]+ @@ -324,7 +360,7 @@ class UserController $this->context->stylesheets []= 'post-list.css'; $this->context->stylesheets []= 'post-small.css'; $this->context->stylesheets []= 'paginator.css'; - if ($this->config->browsing->endlessScrolling) + if ($this->context->user->hasEnabledEndlessScrolling()) $this->context->scripts []= 'paginator-endless.js'; $this->context->subTitle = $name; diff --git a/src/Models/Model_User.php b/src/Models/Model_User.php index 4a3f7aa4..c1f9f0ee 100644 --- a/src/Models/Model_User.php +++ b/src/Models/Model_User.php @@ -41,6 +41,8 @@ class Model_User extends RedBean_SimpleModel $this->settings = $settings; } + + public function hasEnabledSafety($safety) { return $this->getSetting('safety-' . $safety) !== false; @@ -64,6 +66,21 @@ class Model_User extends RedBean_SimpleModel } } + public function hasEnabledEndlessScrolling() + { + $ret = $this->getSetting('endless-scrolling'); + if ($ret === null) + $ret = \Chibi\Registry::getConfig()->browsing->endlessScrollingDefault; + return $ret; + } + + public function enableEndlessScrolling($enabled) + { + $this->setSetting('endless-scrolling', (bool) $enabled); + } + + + public static function validateUserName($userName) { $userName = trim($userName); diff --git a/src/Views/user-settings.phtml b/src/Views/user-settings.phtml new file mode 100644 index 00000000..c06315a1 --- /dev/null +++ b/src/Views/user-settings.phtml @@ -0,0 +1,37 @@ +
+
+ +
+ + + + + +
+
+ +
+ +
+ +
+
+ + + + context->transport->success === true): ?> +

Browsing settings updated!

+ context->transport->errorMessage)): ?> +

Error: context->transport->errorMessage ?>

+ + +
+ + +
+
+ diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml index 88de28f2..917d4176 100644 --- a/src/Views/user-view.phtml +++ b/src/Views/user-view.phtml @@ -121,6 +121,16 @@ + context->transport->tab == 'settings'): ?> +
  • + +
  • + + + Browsing settings + +
  • + context->transport->tab == 'edit'): ?>
  • @@ -152,7 +162,9 @@ renderFile('post-list') ?> - context->transport->tab == 'edit'): ?> + context->transport->tab == 'settings'): ?> + renderFile('user-settings') ?> + context->transport->tab == 'edit'): ?> renderFile('user-edit') ?> context->transport->tab == 'delete'): ?> renderFile('user-delete') ?>