public static function work(&$controllerContext, &$viewContext) { $queue = new Queue(Config::$userQueuePath); $queueItem = new QueueItem(strtolower($controllerContext->userName)); $j['user'] = $controllerContext->userName; $j['pos'] = $queue->seek($queueItem); $viewContext->layoutName = 'layout-json'; $viewContext->json = $j; }
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') { $controllerContext->cache->bypass(true); $viewContext->userName = $controllerContext->userName; $viewContext->viewName = 'error-user-not-found'; $viewContext->meta->title = 'User not found — ' . Config::$title; 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) { $queue = new Queue(Config::$userQueuePath); $queueItem = new QueueItem(strtolower($controllerContext->userName)); $user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]); $profileAge = time() - strtotime($user->processed); $banned = BanHelper::getUserBanState($controllerContext->userName) != BanHelper::USER_BAN_NONE; if ($profileAge > Config::$userQueueMinWait and !$banned && Config::$enqueueEnabled) { $queue->enqueue($queueItem); } $j['user'] = $controllerContext->userName; $j['pos'] = $queue->seek($queueItem); $viewContext->layoutName = 'layout-json'; $viewContext->json = $j; }