src/Controller/basePages.php line 225

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use App\Service\sessionManager;
  9. use App\Service\dbincl;
  10. use App\Service\elasticCon;
  11. use App\Service\elasticTrends;
  12. use Elastic\EnterpriseSearch\AppSearch\Request as eRequest;
  13. use Elastic\EnterpriseSearch\AppSearch\Schema as eSchema;
  14. class basePages extends AbstractController
  15. {
  16.   /**
  17.    * @Route("/", name="index_site")
  18.    */
  19.   public function index_site(dbincl $db_i): Response
  20.   {
  21.     $acc = new sessionManager([01]);
  22.     $recommendations = [];
  23.     $db $db_i->set();
  24.     $resultsIds mysqli_query($db[0], "SELECT DISTINCT t1.product_id, t1.id FROM variations as t1 INNER JOIN products as t2 ON t1.product_id=t2.id WHERE t1.active=1 AND t2.active=1 AND t2.inindex=1 ORDER BY id DESC LIMIT 40");
  25.     $products = [];
  26.     while ($row mysqli_fetch_assoc($resultsIds)) {
  27.       $products[] = $row['id'];
  28.     }
  29.     shuffle($products);
  30.     $products implode(","array_slice($products012));
  31.     $newestResults mysqli_query($db[0], "SELECT t1.id, IF(t1.about_photos = '[]', t2.about_photos, t1.about_photos) as photos, t1.price_mode, t1.price_normal, t1.price_discount, IF(t1.about_name = '', t2.about_name, t1.about_name) as a_name FROM variations as t1 INNER JOIN products as t2 ON t1.product_id=t2.id WHERE t1.id IN ($products)");
  32.     $products = [];
  33.     while ($row mysqli_fetch_assoc($newestResults)) {
  34.       $photos json_decode($row['photos'], true);
  35.       if(isset($photos[0])){
  36.         $photoUrl $photos[0]['url'];
  37.       }else{
  38.         $photoUrl "https://srv1.cnts.venderes.com/resources/uploads/items/@default.png";
  39.       }
  40.       $row['photos'] = $photoUrl;
  41.       $row['productHash'] = substr(bin2hex(base64_decode(md5(($row['id']*3) . "vndpri"))), 010);
  42.       $products[] = $row;
  43.     }
  44.     $recommendations['newest'] = $products;
  45.     $eltrends = new elasticTrends($db);
  46.     $allData $eltrends->trendsDefault();
  47.     $recommendations['popular'] = $allData;
  48.     return $this->render('basePages/template.html.twig', [
  49.       'contentType' => "index_page",
  50.       'acc' => ['if' => $acc->isLogged(), 'data' => $acc->data()],
  51.       'title' => "Pagrindinis",
  52.       'content' => [
  53.         'recommendations' => $recommendations
  54.       ]
  55.     ]);
  56.   }
  57.   /**
  58.    * @Route("/search", name="search_site")
  59.    */
  60.   public function search_site(Request $request): Response
  61.   {
  62.     $acc = new sessionManager([01]);
  63.     $term $request->query->get('q');
  64.     $config = [
  65.       '@term' => ($term === null '' $term),
  66.       '@data' => new \stdClass()
  67.     ];
  68.     return $this->render('basePages/template.html.twig', [
  69.       'contentType' => "search_page",
  70.       'acc' => ['if' => $acc->isLogged(), 'data' => $acc->data()],
  71.       'title' => "Paieška - " $term,
  72.       'content' => [
  73.         'term' => $term,
  74.         'config' => $config
  75.       ]
  76.     ]);
  77.   }
  78.   /**
  79.    * @Route("/product/{id}-{hash}", name="product_site", requirements={"id"="\d+", "hash"="^[a-z0-9]{10}$"})
  80.    */
  81.   public function product_site($id$hashdbincl $db_i): Response
  82.   {
  83.     $acc = new sessionManager([01]);
  84.     $db $db_i->set();
  85.     $contentType 'product_page';
  86.     if($hash != substr(bin2hex(base64_decode(md5(($id*3) . "vndpri"))), 010)){
  87.       $contentType 'product_page@notfound';
  88.     }else{
  89.       $product mysqli_query($db[0], "SELECT
  90.       t1.id, t1.product_id, t1.seller_id, t1.brand, t1.price_mode, t1.price_normal, t1.price_discount, t1.about_photos as t1_a_photos, t2.about_photos as t2_a_photos,
  91.       IF(t1.about_name = '', t2.about_name, t1.about_name) as a_name,
  92.       IF(t1.about_description = '', t2.about_description, t1.about_description) as a_description,
  93.       IF(t1.about_redirect = '[]', t2.about_redirect, t1.about_redirect) as a_redirect_temp
  94.       FROM variations as t1 INNER JOIN products as t2 ON t1.product_id=t2.id WHERE t1.id='$id' AND t1.active=1 AND t2.active=1 AND t2.inindex=1 LIMIT 1");
  95.       if(mysqli_num_rows($product) == 0){
  96.         $contentType 'product_page@notfound';
  97.       }
  98.     }
  99.     $content = [];
  100.     $allok = ($contentType == 'product_page');
  101.     $titleVal 'Prekė nerasta';
  102.     if($allok){
  103.       $product_info mysqli_fetch_assoc($product);
  104.       $content['aboutProduct'] = $product_info;
  105.       $content['aboutProduct']['about_photos'] = array_map(function($v) { return ['url' => $v['url']]; }, array_merge(json_decode($product_info['t1_a_photos'], true), json_decode($product_info['t2_a_photos'], true)));
  106.       //$content['aboutProduct']['about_photos'] = array_merge($content['aboutProduct']['about_photos'], $content['aboutProduct']['about_photos']);
  107.       //$content['aboutProduct']['about_photos'] = array_merge($content['aboutProduct']['about_photos'], $content['aboutProduct']['about_photos']);
  108.       $content['wish'] = [];
  109.       $content['wish']['hash'] = ($acc->isLogged() ? $id "-" rtrim(base64_encode(hex2bin(md5("wish-vnd-" $id "-" $acc->data()['id']))), "=") : '');
  110.       $content['wish']['status'] = false;
  111.       if($acc->isLogged()){
  112.         $my_id $acc->data()['id'];
  113.         $wishlistit mysqli_query($db[0], "SELECT id FROM users_wishlist WHERE owner='$my_id' AND product='$id' LIMIT 1");
  114.         if(mysqli_num_rows($wishlistit) > 0){
  115.           $content['wish']['status'] = true;
  116.         }
  117.       }
  118.       $titleVal $product_info['a_name'];
  119.       $sellerNameTemp json_decode($product_info['a_redirect_temp'], true)['d'];
  120.       $content['aboutSeller']['name'] = parse_url($sellerNameTemp)['host'];
  121.       $todayhuman date('Ymd'); $allStats = ['days' => [], 'vals' => []]; $metaStats = [];
  122.       $stats mysqli_query($db[0], "SELECT value, day FROM price_changes WHERE variation_id={$id} AND NOT day='{$todayhuman}' ORDER BY day DESC LIMIT 7");
  123.       while($statrow mysqli_fetch_assoc($stats)){
  124.         $date substr($statrow['day'], 04) . "-" substr($statrow['day'], 42) . "-" substr($statrow['day'], 62);
  125.         $allStats['days'][] = $date;
  126.         $allStats['vals'][] = number_format($statrow['value'] / 1002'.''');
  127.         $metaStats[] = $statrow['value'];
  128.       }
  129.       $allStats['days'] = array_reverse($allStats['days']);
  130.       $allStats['vals'] = array_reverse($allStats['vals']);
  131.       //Today stats
  132.       $today_price = ($product_info['price_mode'] == $product_info['price_discount'] : $product_info['price_normal']);
  133.       $allStats['days'][] = date('Y-m-d');
  134.       $allStats['vals'][] = number_format($today_price 1002'.''');
  135.       $metaStats[] = $today_price;
  136.       //*Today stats
  137.       $allStats['yax'] = [0,0];
  138.       if(isset($metaStats[0])){
  139.         $allStats['yax'] = [floor(min($metaStats) / 100) - 5ceil(max($metaStats) / 100) + 5];
  140.         $allStats['yax'][0] = ($allStats['yax'][0] < $allStats['yax'][0]);
  141.       }
  142.       $content['stats'] = $allStats;
  143.     }else{
  144.       $eltrends = new elasticTrends($db);
  145.       $content['trends'] = $eltrends->trendsDefault();
  146.     }
  147.     return $this->render('basePages/template.html.twig', [
  148.       'contentType' => $contentType,
  149.       'acc' => ['if' => $acc->isLogged(), 'data' => $acc->data()],
  150.       'title' => $titleVal,
  151.       'content' => $content
  152.     ]);
  153.   }
  154.   /**
  155.    * @Route("/product/fromSearch/{id}-{hash}", name="product_site_stats", requirements={"id"="\d+", "hash"="^[a-z0-9]{10}$"})
  156.    */
  157.   public function product_site_stats($id$hashRequest $request): Response
  158.   {
  159.     if($hash == substr(bin2hex(base64_decode(md5(($id*3) . "vndpri"))), 010)){
  160.       $source $request->query->get('_source');
  161.       $requestid $request->query->get('requestId');
  162.       $sign $request->query->get('idSign');
  163.       $posBef $request->query->get('posBef');
  164.       $pos $request->query->get('pos');
  165.       $query $request->query->get('query');
  166.       if(!in_array(null, [$source$requestid$sign$posBef$pos])){
  167.         $query urldecode($query);
  168.         $sign bin2hex(base64_decode($sign));
  169.         if(
  170.           in_array($source, ['organicSearch']) &&
  171.           filter_var($posFILTER_VALIDATE_INT) && filter_var($posBefFILTER_VALIDATE_INT) !== false &&
  172.           $pos $posBef &&
  173.           md5($requestid "vndrs-search-sign" dechex($posBef) . "/" $query) == $sign
  174.         ){
  175.           $clientCon = new elasticCon();
  176.           $client $clientCon->client();
  177.           $appSearch $client->appSearch();
  178.           $actReq = new eSchema\ClickParams($query$id);
  179.           $actReq->request_id $requestid;
  180.           $actReq->tags = ['source:''source:'.$source];
  181.           $result $appSearch->logClickthrough(
  182.             new eRequest\LogClickthrough('prices-items'$actReq)
  183.           );
  184.         }
  185.       }
  186.     }
  187.     //Check and insert stats
  188.     return $this->redirectToRoute('product_site', ['id' => $id'hash' => $hash]);
  189.   }
  190.   /**
  191.    * @Route("/product/redirect/{id}/{hash}", name="productredirect_site", requirements={"id"="\d+", "hash"="^[a-z0-9]{10}$"})
  192.    */
  193.   public function productredirect_site($id$hashdbincl $db_i): Response
  194.   {
  195.     if($hash == substr(bin2hex(base64_decode(md5(($id*3) . "vndpri"))), 010)){
  196.       $db $db_i->set();
  197.       $product mysqli_query($db[0], "SELECT IF(t1.about_redirect = '[]', t2.about_redirect, t1.about_redirect) as a_redirect
  198.       FROM variations as t1 INNER JOIN products as t2 ON t1.product_id=t2.id WHERE t1.id='$id' AND t1.active=1 AND t2.active=1 AND t2.inindex=1 LIMIT 1");
  199.       if(mysqli_num_rows($product) > 0){
  200.         $product_info mysqli_fetch_assoc($product);
  201.         $redirect_path json_decode($product_info['a_redirect'], true);
  202.         if(isset($redirect_path['d']) && isset($redirect_path['p'])){
  203.           return $this->redirect($redirect_path['d'] . $redirect_path['p']);
  204.         }
  205.       }
  206.     }
  207.     return $this->redirectToRoute('product_site', ['id' => $id'hash' => $hash]);
  208.   }
  209.   /**
  210.    * @Route("/auth/{log_type}", name="auth_site", requirements={"log_type"="login|register|recover"})
  211.    */
  212.   public function auth_site($log_typeRequest $request): Response
  213.   {
  214.     $acc = new sessionManager([0]);
  215.     $routeTo urldecode($request->query->get('routeTo'));
  216.     $index_path $this->generateUrl('index_site');
  217.     return $this->redirect($acc->toAuth($index_path, ($routeTo == '' $index_path $routeTo), $log_type));
  218.   }
  219. }
  220. ?>