===== PART 1/12 ===== loadComponent('Cookie'); $this->loadComponent('Captcha'); } public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->viewBuilder()->setLayout('front'); $this->Auth->allow(['shorten', 'view', 'go', 'popad']); // if (in_array($this->getRequest()->getParam('action'), ['view', 'go', 'popad'])) { // $this->getEventManager()->off($this->Security); // } } public function view($alias = null) { $this->setResponse( $this->getResponse() ->withHeader('X-Frame-Options', 'SAMEORIGIN') ->withHeader('X-Robots-Tag', 'noindex, nofollow') ); if (!$alias) { throw new NotFoundException(__('404 Not Found')); } /** * @var \App\Model\Entity\Link $link */ $link = $this->Links->find() //->contain(['Users']) ->contain([ 'Users' => [ 'fields' => ['id', 'username', 'status', 'disable_earnings', 'no_campaign_behavior', 'no_campaign_message'], ], ]) ->where([ 'Links.alias' => $alias, 'Links.status <>' => 3, 'Users.status' => 1, ]) ->first(); if (!$link) { throw new NotFoundException(__('404 Not Found')); } $this->set('link', $link); if ((bool)get_option('maintenance_mode', false)) { return $this->redirect($link->url, 307); } $link_user_plan = get_user_plan($link->user_id); $this->set('link_user_plan', $link_user_plan); if ($link_user_plan->link_expiration && !empty($link->expiration) && $link->expiration->isPast()) { throw new ForbiddenException(__('The link has been expired')); } $detector = new \Detection\MobileDetect(); if ((bool)$detector->is("Bot")) { if ((bool)validCrawler()) { return $this->redirect($link->url, 301); } } $plan_disable_ads = $plan_disable_captcha = $plan_onetime_captcha = $plan_direct = false; if ($this->Auth->user()) { $auth_user_plan = get_user_plan($this->Auth->user('id')); if ($auth_user_plan->disable_ads) { $plan_disable_ads = true; } if ($auth_user_plan->disable_captcha) { $plan_disable_captcha = true; } if ($auth_user_plan->onetime_captcha) { $plan_onetime_captcha = true; } if ($auth_user_plan->direct) { $plan_direct = true; } } if ($link_user_plan->visitors_remove_captcha) { $plan_disable_captcha = true; } $this->set('plan_disable_ads', $plan_disable_ads); $ad_type = $link->ad_type; if (!array_key_exists($ad_type, get_allowed_ads($link_user_plan))) { $ad_type = array_key_first(get_allowed_ads($link_user_plan)); } if ($link->user_id == 1) { $ad_type = get_option('anonymous_default_advert', 1); } if ($ad_type == 3) { $types = [1, 2]; $ad_type = $types[array_rand($types, 1)]; } $this->set('ad_type', $ad_type); $this->setRefererCookie($link->alias); // No Ads if ($plan_direct || $ad_type == 0) { $this->updateLinkHits($link); $this->addNormalStatisticEntry($link, $ad_type, [ 'ci' => 0, 'cui' => 0, 'cii' => 0, ], get_ip(), 10); return $this->redirect($link->url, 301); } $ad_captcha_above = get_option('ad_captcha_above', ''); $ad_captcha_below = get_option('ad_captcha_below', ''); if ($plan_disable_ads) { $ad_captcha_above = ''; $ad_captcha_below = ''; } $this->set('ad_captcha_above', $ad_captcha_above); $this->set('ad_captcha_below', $ad_captcha_below); $display_blog_post_shortlink = get_option('display_blog_post_shortlink', 'none'); $post = ''; if (in_array($display_blog_post_shortlink, ['latest', 'random'])) { $order = ['RAND()']; if ('latest' === $display_blog_post_shortlink) { $order = ['Posts.id' => 'DESC']; } $posts = TableRegistry::getTableLocator()->get('Posts'); $post = $posts->find() ->where(['Posts.published' => 1]) ->order($order) ->first(); } $this->set('post', $post); $displayCaptchaShortlink = $this->displayCaptchaShortlink($plan_disable_captcha, $plan_onetime_captcha); $this->set('displayCaptchaShortlink', $displayCaptchaShortlink); if ($this->getRequest()->getData('action') !== 'captcha') { $pagesNumber = (int)\get_option('continue_pages_number', 0); if ($pagesNumber > 0) { $page = (int)$this->getRequest()->getData('page', 1); if ($page <= $pagesNumber) { $this->set('page', $page); $this->viewBuilder()->setLayout('captcha'); return $this->render('page'); } } } $this->viewBuilder()->setLayout('captcha'); $this->render('captcha'); if ( !$displayCaptc