Example #1
0
 public static function preWork(&$controllerContext, &$viewContext)
 {
     $controllerContext->cache->setPrefix($controllerContext->userName);
     if (BanHelper::getUserBanState($controllerContext->userName) == BanHelper::USER_BAN_TOTAL) {
         $controllerContext->cache->bypass(true);
         $viewContext->userName = $controllerContext->userName;
         $viewContext->viewName = 'error-user-blocked';
         $viewContext->meta->title = 'User blocked — ' . Config::$title;
         return;
     }
     $module = $controllerContext->module;
     HttpHeadersHelper::setCurrentHeader('Content-Type', $module::getContentType());
     $viewContext->media = $controllerContext->media;
     $viewContext->module = $controllerContext->module;
     $viewContext->meta->noIndex = true;
     $viewContext->contentType = $module::getContentType();
     if ($viewContext->contentType != 'text/html') {
         $viewContext->layoutName = 'layout-raw';
     }
     Database::selectUser($controllerContext->userName);
     $user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]);
     if (empty($user)) {
         if (!isset($_GET['referral']) || $_GET['referral'] !== 'search') {
             $uri = IndexControllerIndexModule::url();
             HttpHeadersHelper::setCurrentHeader('Location', $uri);
             return;
         }
         $queue = new Queue(Config::$userQueuePath);
         $queueItem = new QueueItem(strtolower($controllerContext->userName));
         $queue->enqueue($queueItem);
         $viewContext->queuePosition = $queue->seek($queueItem);
         $controllerContext->cache->bypass(true);
         //try to load cache, if it exists
         $url = $controllerContext->url;
         if ($controllerContext->cache->exists($url)) {
             $controllerContext->cache->load($url);
             flush();
             $viewContext->layoutName = null;
             $viewContext->viewName = null;
             return;
         }
         $viewContext->userName = $controllerContext->userName;
         $viewContext->viewName = 'error-user-enqueued';
         $viewContext->meta->title = 'User enqueued — ' . Config::$title;
         return;
     }
     $viewContext->user = $user;
     $viewContext->meta->styles[] = '/media/css/menu.css';
     $viewContext->updateWait = Config::$userQueueMinWait;
     $module = $controllerContext->module;
     $module::preWork($controllerContext, $viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $username = !empty($_POST['user-name']) ? trim($_POST['user-name']) : '';
     if (empty($username)) {
         $viewContext->layoutName = null;
         $uri = IndexControllerIndexModule::url();
         HttpHeadersHelper::setCurrentHeader('Location', $uri);
         return;
     }
     if (!preg_match('#^' . UserController::getUserRegex() . '$#', $username)) {
         $viewContext->viewName = 'error-user-invalid';
         return;
     }
     $viewContext->layoutName = null;
     $uri = UserControllerProfileModule::url($username);
     HttpHeadersHelper::setCurrentHeader('Location', $uri . '?referral=search');
 }