?> </ul></nav> </div> <?php if (!empty($Database)) { if ($signedIn) { $Notifications = Notifications::get(null, Notifications::UNREAD_ONLY); ?> <section class="notifications"<?php echo empty($Notifications) ? ' style="display:none"' : ''; ?> > <h2>Unread notifications</h2> <?php try { echo Notifications::getHTML($Notifications); } catch (Throwable $e) { error_log('Exception caught when rendering notifications: ' . $e->getMessage() . "\n" . $e->getTraceAsString()); echo '<ul class="notif-list"><li>An error prevented the notifications from appearing. If this persists, <a class="send-feedback">let us know</a>.</li></ul>'; } ?> </section> <?php } ?> <section class="<?php echo $signedIn ? 'welcome' : 'login'; ?> "> <h2><?php echo $signedIn ? 'Signed in as' : 'Welcome!';
use App\Posts; use App\Response; /** @var $signedIn bool */ /** @var $data string */ if (!POST_REQUEST) { CoreUtils::notFound(); } if (!$signedIn) { Response::fail(); } CSRFProtection::protect(); list($action, $data) = explode('/', $data . '/'); switch ($action) { case 'get': try { $Notifications = Notifications::getHTML(Notifications::get(null, Notifications::UNREAD_ONLY), NOWRAP); Response::done(array('list' => $Notifications)); } catch (Throwable $e) { error_log('Exception caught when fetching notifications: ' . $e->getMessage() . "\n" . $e->getTraceAsString()); Response::fail('An error prevented the notifications from appearing. If this persists, <a class="send-feedback">let us know</a>.'); } break; case 'mark-read': $nid = intval($data, 10); $Notif = $Database->where('id', $nid)->where('user', $currentUser->id)->getOne('notifications'); if (empty($Notif)) { Response::fail("The notification (#{$nid}) does not exist"); } $read_action = (new Input('read_action', 'string', array(Input::IS_OPTIONAL => true, Input::IN_RANGE => [null, 10], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_INVALID => 'Action (@value) is invalid', Input::ERROR_RANGE => 'Action cannot be longer than @max characters'))))->out(); if (!empty($read_action)) { if (empty(Notifications::$ACTIONABLE_NOTIF_OPTIONS[$Notif['type']][$read_action])) {