src/Controller/DefaultController.php line 123

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\Mapping\Entity;
  4. use Doctrine\Persistence\ObjectManager;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. //use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Console\Input\ArrayInput;
  10. use Symfony\Bundle\FrameworkBundle\Console\Application;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Symfony\Component\Console\Output\BufferedOutput;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Bundle\MonologBundle\SwiftMailer\Swift_Message;
  15. use Monolog\Handler\StreamHandler;
  16. use Monolog\Handler\SyslogHandler;
  17. use Monolog\ErrorHandler;
  18. use Monolog\Logger;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Symfony\Component\HttpKernel\KernelInterface;
  21. use Symfony\Component\Mailer\MailerInterface;
  22. use Symfony\Component\Mime\Email;
  23. use App\Entity\Currency;
  24. use App\Entity\Eshop;
  25. use App\Entity\Gallery;
  26. use App\Entity\Gallery3D;
  27. use App\Entity\GalleryItem;
  28. use App\Entity\Language;
  29. use App\Entity\Module;
  30. use App\Entity\PriceLevel;
  31. use App\Entity\Product;
  32. use App\Entity\ProductGroup;
  33. use App\Entity\RedactionList;
  34. use App\Entity\Server;
  35. use App\Entity\Service;
  36. use App\Entity\User;
  37. use Symfony\Bridge\Twig\Mime\BodyRenderer;
  38. use Symfony\Component\Mailer\Transport;
  39. use Symfony\Component\Mailer\Mailer;
  40. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  41. use Symfony\Component\Mime\Address;
  42. use Twig\Environment;
  43. use Twig\Loader\FilesystemLoader;
  44. class DefaultController extends AbstractController
  45. {
  46.     protected string $databaseUser "root";
  47.     protected string $databasePassword "pswdb33";
  48.     protected string $translateBaseUrl 'https://translate.yandex.net/api/v1.5/tr.json/translate';
  49.     protected string $translateApiKey 'trnsl.1.1.20200423T052136Z.ae351a8275ee45f3.fe0d2bd852ec5d9c88b7a00ebe8d5260fc589c35';
  50.     protected MailerInterface $mailer;
  51.     public function __construct(
  52.         protected ManagerRegistry $doctrine,
  53.                     KernelInterface $appKernel,
  54.                     MailerInterface $mailer
  55.     ) {
  56.         $this->doctrine $doctrine;
  57.         $this->appKernel $appKernel;
  58.         $this->mailer $mailer;
  59.     }
  60.     public function init(Request $request)
  61.     {
  62.         $session $request->getSession();
  63.         $em $this->doctrine->getManager();
  64.         /* we set server info */
  65.         //$session->set('label', null);
  66.         /*
  67.         print("<br>qqw php ver: ");
  68.         print_r(phpversion());
  69.         print("<br>qqw label: ".$session->get('label'));
  70.         */
  71.         //$request->setLocale('cz');
  72. //        print(phpinfo());
  73.         //
  74. //        print("<br>qqw label: ".$session->get('label'));
  75.         //$em = $this->em;
  76.         //$session->remove('label');
  77.         /* setting default label/server/brand/ */
  78.         if(empty($session->get('label'))) {
  79.             /* we try to get http host and choose label */
  80.             //print("<br>qqw host: ".$_SERVER['HTTP_HOST']);
  81.             $hostServer $em->getRepository(Server::class)->getServerFromHost($_SERVER['HTTP_HOST']);
  82. //            print("<br>qqw hostServer: ".$_SERVER['HTTP_HOST']);
  83. //            \Doctrine\Common\Util\Debug::dump($hostServer);
  84.             if (empty($hostServer)) {
  85.                 $this->addFlash('error''Please add Server instance.');
  86.                 return;
  87.             }
  88.             $session->set('label'$hostServer->getLabel());
  89.             //$session->set('label', 'webexciter.com');
  90. //            print("<br>QQW getting default label: ".$session->get('label'));
  91.             $server $this->getServerByLabel($session->get('label'));
  92.             $session->set('server'$server);
  93.             /*
  94.             print('<hr>qqw getServices: ');
  95.             \Doctrine\Common\Util\Debug::dump($session->get('server')->getServices());
  96.             */
  97.             /* we load languages into session */
  98.             $langList $em->getRepository(Language::class)->getLanguageList();
  99.             $session->set('langList'$langList);
  100.             /* we load currencies into session */
  101.             $currencyList $em->getRepository(Currency::class)->getCurrencyList();
  102.             $session->set('currencyList'$currencyList);
  103.             /* we setup server preferred language */
  104.             $lang $em->getRepository(Language::class)->getLanguage($server->getPreferredLanguageId());
  105.             $session->set('lang'$lang);
  106. //            print("<br>QQW lang 1: ".$lang->getLangKey());
  107.             /*
  108.             print("<br>QQW locale 1: ".$request->getLocale());
  109.             if(empty($session->get('lang')->getLangKey())) {
  110.               $request->setLocale($session->get('lang')->getLangKey());
  111.             }
  112.             */
  113.             $request->setLocale($session->get('lang')->getLangKey());
  114.             /* we setup server preferred currency */
  115.             $currency $em->getRepository(Currency::class)->getCurrency($server->getPreferredCurrencyId());
  116.             $session->set('currency'$currency);
  117.         }
  118.         /*
  119.         print("<hr>qqw locale: ");
  120.         print_r($request->getLocale());
  121.         print("<hr>qqw label: ".$session->get('label'));
  122.         print("<hr>qqw langList: ");
  123.         print_r($session->get('langList'));
  124.         print("<hr>qqw currencyList: ");
  125.         print_r($session->get('currencyList'));
  126.         print("<hr>qqw lang: ");
  127.         print_r($session->get('lang'));
  128.         print("<hr>qqw currency: ");
  129.         print_r($session->get('currency'));
  130.         */
  131.         //print("<br>QQW locale 2: ".$request->getLocale());
  132.         /* setting new label/server/brand/ */
  133.         if(!empty($request->query->get('newlabel'))) {
  134.             $session->set('label'$request->query->get('newlabel'));
  135.             //print("<br>QQW setting new label");
  136.             $server $this->getServerByLabel($session->get('label'));
  137.             $session->set('server'$server);
  138.             /* we load languages into session */
  139.             $langList $em->getRepository(Language::class)->getLanguageList();
  140.             $session->set('langList'$langList);
  141.             /* we load currencies into session */
  142.             $currencyList $em->getRepository(Currency::class)->getCurrencyList();
  143.             $session->set('currencyList'$currencyList);
  144.             /* we setup server preferred language */
  145.             $lang $em->getRepository(Language::class)->getLanguage($server->getPreferredLanguageId());
  146.             $session->set('lang'$lang);
  147.             /* we setup server preferred currency */
  148.             $currency $em->getRepository(Currency::class)->getCurrency($server->getPreferredCurrencyId());
  149.             $session->set('currency'$currency);
  150.         }
  151.         /* setting new currency */
  152.         if(!empty($request->query->get('newcurrency'))) {
  153.             //print("<br>QQW setting new currency");
  154.             $currency $em->getRepository(Currency::class)->getCurrencyByKey($request->query->get('newcurrency'));
  155.             if(!empty($currency)) {
  156.                 $session->set('currency'$currency);
  157.                 $this->addFlash('notice''Currency was changed to '.$currency->getCurrencyName().'.');
  158.             }
  159.         }
  160.         /* setting new eshop currency */
  161.         /*         - it is done in EshopController @Route("/eshop/{eshopId}/eshopNewcurr", name="eshopNewcurr")
  162.         if(!empty($request->query->get('newEshopCurrency'))) {
  163.             //print("<br>QQW setting new eshop currency");
  164.             $currency = $em->getRepository('App:Currency')->getCurrencyByKey($request->query->get('newEshopCurrency'));
  165.             if(!empty($currency)) {
  166.                 $session->set('eshopCurrency', $currency);
  167.             foreach($session->getFlashBag() as $message) {
  168.                    print('<br>qqw message X');
  169.             }
  170.                 $this->addFlash('notice', 'E-shop Currency was changed to '.$currency->getCurrencyName().'.');
  171.             }
  172.         }
  173.          */
  174.         /* we set locale according to lang */
  175.         /* this is done in event listener */
  176.         //$request->setLocale($session->get('lang')->getLangKey());
  177.         //print("<br>QQW locale: ".$request->getLocale());
  178.         //$translator->getCatalogue($request->getLocale());
  179.         //print("<br>QQW label: ".$session->get('label'));
  180.         /* we set info */
  181.     }
  182.     public function getServerByLabel($label)
  183.     {
  184.         /* print("<br>QQW getting server from label: ".$label); */
  185.         $em $this->doctrine->getManager();
  186.         $server $em->getRepository(Server::class)->getServerFromLabel($label);
  187.         return $server;
  188.     }
  189.     public function getPageHeader(Request $request)
  190.     {
  191.         $session $request->getSession();
  192.         $em $this->doctrine->getManager();
  193.         $user null;
  194.         $serviceCollectionn null;
  195.         $moduleCollection null;
  196.         /* we get current user */
  197.         if(!empty($session->get('user'))) {
  198.             $currentUserId $session->get('user')->getUserId();
  199.             $user $em->getRepository(User::class)->getUser($currentUserId);
  200.             $serviceCollection $em->getRepository(Service::class)->getServiceList();
  201.             $moduleCollection $em->getRepository(Module::class)->getLiveModuleList();
  202.         }
  203.         //we build service array
  204.         $services = array();
  205.         if(!empty($serviceCollection)) {
  206.             foreach($serviceCollection as $service) {
  207.                 $isService $em->getRepository(User::class)->userHasService($user$service);
  208.                 if($isService) {
  209.                     $serviceId $service->getServiceId();
  210.                     $services[$serviceId] = $service;
  211.                 }
  212.             }
  213.         }
  214.         //we build module array
  215.         $modules = array();
  216.         if(!empty($moduleCollection)) {
  217.             foreach($moduleCollection as $module) {
  218.                 $isModule $em->getRepository(User::class)->userHasModule($user$module);
  219.                 if($isModule and $module->getIsLive() == 1) {
  220.                     $moduleId $module->getModuleId();
  221.                     $modules[$moduleId] = $module;
  222.                 }
  223.             }
  224.         }
  225.         $headerData = array();
  226.         $headerData['headerMessage'] = "";
  227.         $headerData['user'] = $user;
  228.         $headerData['services'] = $services;
  229.         $headerData['modules'] = $modules;
  230.         //we load services list of the server into session
  231.         if(!empty($session->get('server')) && (empty($session->get('server')->getServices()) || count($session->get('server')->getServices())==0)) {
  232.             $server $em->getRepository(Server::class)->getServer($session->get('server')->getServerId());
  233.             foreach($server->getServices() as $service) {
  234.                 if($service->getIsLive() == 1) {
  235.                     $session->get('server')->addService($service);
  236.                 }
  237.                 /*
  238.                 print('<hr>QQW session service: ');
  239.                 \Doctrine\Common\Util\Debug::dump($service);
  240.                 */
  241.             }
  242.         }
  243.         return $headerData;
  244.     }
  245.     public function getSeoData(Request $request)
  246.     {
  247.         $session $request->getSession();
  248.         $seoData = array();
  249.         $seoData['seoTitle'] = "SEO Title";
  250.         // print('<hr>QQW SERVER HEADER: ');  
  251.         // \Doctrine\Common\Util\Debug::dump($session->get('server')->getServices()); 
  252.         return $seoData;
  253.     }
  254.     public function checkUserEntities(Request $request)
  255.     {
  256.         $session $request->getSession();
  257.         $em $this->doctrine->getManager();
  258.         //print("<br>QQW checkUserEntities:");
  259.         /* temporary setting - we generate always entity */
  260.         $this->generateUserEntities();
  261.         /* we check user entities */
  262.         if(empty($session->get('user')->getDateEntitiesUpdated())) {
  263.             $this->generateUserEntities();
  264.             $dateTimeNow = new \DateTime("now");
  265.             /* we set entity update date in session */
  266.             $session->get('user')->setDateEntitiesUpdated($dateTimeNow);
  267.             /* we set entity update date in db */
  268.             $userId $session->get('user')->getUserId();
  269.             $user $em->getRepository(User::class)->getUser($userId);
  270.             $user->setDateEntitiesUpdated($dateTimeNow);
  271.             $em->flush();
  272.         }
  273.     }
  274.     /**
  275.      * @throws \Exception
  276.      */
  277.     public function generateUserEntities()
  278.     {
  279.         //define('STDIN',fopen("php://stdin","r"));
  280.         if (!defined('STDIN')) define('STDIN',fopen("php://stdin","r"));
  281.         /* we generate entities for the user */
  282. //        print("<br>Generate entities for the user.");
  283.         $dem $this->doctrine->getManager('dynamic_em');
  284.         $application = new Application($this->appKernel);
  285.         $application->setAutoExit(false);
  286.         // Update schema
  287.         //$options = array('command' => 'doctrine:schema:update','--force' => true, '--em' => 'dynamic_em');
  288.         //$options = array('command' => 'doctrine:migrations:migrate', '--em' => 'dynamic_em');
  289.         //$options = array('command' => 'doctrine:migrations:migrate --em=dynamic_em');
  290.         $input = new ArrayInput(array(
  291.             'command' => 'doctrine:migrations:migrate',
  292.             '--em' => 'dynamic_em'
  293.         ));
  294.         $output = new BufferedOutput();
  295.         $application->run($input$output);
  296.         // return the output, don't use if you used NullOutput()
  297.         $content $output->fetch();
  298.         //print(" ... Entities generated.");
  299. //        \Doctrine\Common\Util\Debug::dump($output);
  300.         // return new Response(""), if you used NullOutput()
  301.         return new Response($content);
  302.         //$options = array('command' => 'symfony server:stop');
  303.         //$output = $application->run(new ArrayInput($options));
  304. //        print("<br>Entities generated.");
  305. //        \Doctrine\Common\Util\Debug::dump($output);
  306.         return true;
  307.     }
  308.     public function checkUserDB(Request $request)
  309.     {
  310.         $session $request->getSession();
  311.         $em $this->doctrine->getManager();
  312.         $currentUserId $session->get('user')->getUserId();
  313.         if(!$em->getRepository(User::class)->isUserDB($currentUserId)) {
  314.             $this->createUserDB($request);
  315.             $this->addFlash('notice''User database was created.');
  316.             return false;
  317.         } else {
  318.             return true;
  319.         }
  320.     }
  321.     public function createUserDB(Request $request)
  322.     {
  323.         $session $request->getSession();
  324.         $currentUserId $session->get('user')->getUserId();
  325.         /* we create users db */
  326.         $em $this->doctrine->getManager();
  327.         $currentUser $em->getRepository(User::class)->getUser($currentUserId);
  328.         $userDbName "am_".$currentUser->getUserName();
  329.         $em->getRepository(User::class)->createUserDB($currentUserId$userDbName);
  330.         /* we insert db connection to user entity */
  331.         $currentUser->setDatabaseName($userDbName);
  332.         $currentUser->setDatabaseUser($this->databaseUser);
  333.         $currentUser->setDatabasePassword($this->databasePassword);
  334.         $session->get('user')->setDatabaseName($userDbName);
  335.         $session->get('user')->setDatabaseUser($this->databaseUser);
  336.         $session->get('user')->setDatabasePassword($this->databasePassword);
  337.         /* we persist and save user */
  338.         //$em->persist($user);
  339.         $em->flush();
  340.         return true;
  341.     }
  342.     public function isUserFolder(Request $request)
  343.     {
  344.         $session $request->getSession();
  345.         $currentUserName $session->get('user')->getUserName();
  346.         $imageDir "../public/users/".$currentUserName;
  347.         //print('<br>QQW check image dir: '.$imageDir);
  348.         if (is_dir($imageDir)) {
  349.             return true;
  350.         } else{
  351.             return false;
  352.         }
  353.     }
  354.     public function createUserFolder(Request $request)
  355.     {
  356.         $session $request->getSession();
  357.         $currentUserName $session->get('user')->getUserName();
  358.         $userDir "../public/users/".$currentUserName;
  359.         $imageDir "../public/users/".$currentUserName."/images";
  360.         //print('<br>Create image dir: '.$imageDir);
  361.         if (false === mkdir($userDir0777true) OR false === mkdir($imageDir0777true)) {
  362.             print('<br>Image dir: '.sprintf('Unable to create the "%s" directory'$imageDir));
  363.             //throw new FileException(sprintf('Unable to create the "%s" directory', $imageDir));
  364.             return false;
  365.         }  elseif (!is_writable($imageDir)) {
  366.             print('<br>Image dir: '.sprintf('Unable to write in the "%s" directory'$imageDir));
  367.             //throw new FileException(sprintf('Unable to write in the "%s" directory', $imageDir));
  368.             return false;
  369.         }  else{
  370.             return true;
  371.         }
  372.     }
  373.     public function isUserCustomFolder(Request $request$folderName)
  374.     {
  375.         $session $request->getSession();
  376.         $currentUserName $session->get('user')->getUserName();
  377.         $customDir "../public/users/".$currentUserName."/".$folderName;
  378.         //print('<br>QQW check custom dir: '.$customDir);
  379.         if (is_dir($customDir)) {
  380.             return true;
  381.         } else{
  382.             return false;
  383.         }
  384.     }
  385.     public function createUserCustomFolder(Request $request$folderName)
  386.     {
  387.         $session $request->getSession();
  388.         $currentUserName $session->get('user')->getUserName();
  389.         $userDir "../public/users/".$currentUserName;
  390.         $customDir "../public/users/".$currentUserName."/".$folderName;
  391.         print('<br>Create customDir dir: '.$customDir);
  392.         if (false === mkdir($customDir0777true)) {
  393.             print('<br>Custom dir: '.sprintf('Unable to create the "%s" directory'$customDir));
  394.             //throw new FileException(sprintf('Unable to create the "%s" directory', $customDir));
  395.             return false;
  396.         }  elseif (!is_writable($customDir)) {
  397.             print('<br>Custom dir: '.sprintf('Unable to write in the "%s" directory'$customDir));
  398.             //throw new FileException(sprintf('Unable to write in the "%s" directory', $customDir));
  399.             return false;
  400.         }  else{
  401.             return true;
  402.         }
  403.     }
  404.     public function getUserFolderPaths(Request $request$userName '')
  405.     {
  406.         $userFolderPaths = array();
  407.         $session $request->getSession();
  408.         if(!empty($session->get('user'))) {
  409.             $currentUserName $session->get('user')->getUserName();
  410.         } else {
  411.             $currentUserName $userName;
  412.         }
  413.         $userFolderPaths['user'] = "../public/users/".$currentUserName;
  414.         $userFolderPaths['images'] = "../public/users/".$currentUserName."/images";
  415.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  416.             $userFolderPaths['web'] = "http://".$_SERVER['HTTP_HOST']."/users/".$currentUserName;
  417.             $userFolderPaths['webroot'] = "http://".$_SERVER['HTTP_HOST'];
  418.         } else {
  419.             $userFolderPaths['web'] = "https://".$_SERVER['HTTP_HOST']."/users/".$currentUserName;
  420.             $userFolderPaths['webroot'] = "https://".$_SERVER['HTTP_HOST']."/";
  421.         }
  422.           //print('<br>qqw web path: '.$userFolderPaths['web']);
  423.         return $userFolderPaths;
  424.     }
  425.     public function getUserFolderPathsFromUserId($userId)
  426.     {
  427.         $userFolderPaths = array();
  428.         /* we create users db */
  429.         $em $this->doctrine->getManager();
  430.         $user $em->getRepository(User::class)->getUser($userId);
  431.         $currentUserName $user->getUserName();
  432.         $userFolderPaths['user'] = "../public/users/".$currentUserName;
  433.         $userFolderPaths['images'] = "../public/users/".$currentUserName."/images";
  434.         if($_SERVER['HTTP_HOST'] != 'localhost') {
  435.             $userFolderPaths['web'] = "http://".$_SERVER['HTTP_HOST']."/users/".$currentUserName;
  436.             $userFolderPaths['webroot'] = "http://".$_SERVER['HTTP_HOST'];
  437.         } else {
  438.             $userFolderPaths['web'] = "https://"."www.".$_SERVER['HTTP_HOST']."/alliancemarkets2/public/users/".$currentUserName;
  439.             $userFolderPaths['webroot'] = "https://"."www.".$_SERVER['HTTP_HOST']."/alliancemarkets2/";
  440.         }
  441.         //print('<br>qqw web path: '.$userFolderPaths['web']);
  442.         return $userFolderPaths;
  443.     }
  444.     function parseContent(Request $request$text2Parse) {
  445.         $left 0;
  446.         //find first left bracket
  447.         $left strpos($text2Parse'{');
  448.         //find first right bracket
  449.         $right strpos($text2Parse'}');
  450.         //print("<br>qqw parse element: ");
  451.         $parsedText "";
  452.         if($right>0)
  453.         {
  454.             $parseElement substr($text2Parse$left+1$right-$left-1);
  455.             $textType explode('_'$parseElement);
  456.             if(!empty($textType[1])) {
  457.                 $elementId $textType[1];
  458.             }
  459.             switch($textType[0])
  460.             {
  461.                 case "SLIDESHOW":
  462.                     //we generate the code for the slideshow
  463.                     $startText substr($text2Parse0$right+1);
  464.                     print('<br>QQW SLIDESHOW');
  465.                     //$parsedText = ereg_replace ('{'.$parseElement.'}', $this->getSlideShow($textType[1]), $startText);
  466.                     break; //case "SLIDESHOW":
  467.                 case "INTERACTIVESLIDESHOW":
  468.                     //print('<br>INTERACTIVESLIDESHOW');
  469.                     $startText substr($text2Parse0$right+1);
  470.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getInteractiveSlideShow($elementId), $text2Parse);
  471.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  472.                     $restContentParsed $this->parseContent($request$restContent);
  473.                     $parsedText $startTextParsed.$restContentParsed;
  474.                     break; //case "INTERACTIVESLIDESHOW":
  475.                 case "REDACTIONLIST":
  476.                     $startText substr($text2Parse0$right+1);
  477.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getRedactionList($request$elementId), $startText);
  478.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  479.                     $restContentParsed $this->parseContent($request$restContent);
  480.                     $parsedText $startTextParsed.$restContentParsed;
  481.                     break; //case "REDACTIONLIST":
  482.                 case "PRODUCTSELECTIONGUIDE":
  483.                     $startText substr($text2Parse0$right+1);
  484.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getProductSelectionGuide($elementId), $startText);
  485.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  486.                     $restContentParsed $this->parseContent($request$restContent);
  487.                     $parsedText $startTextParsed.$restContentParsed;
  488.                     break; //case "PRODUCTSELECTIONGUIDE":
  489.                 case "PRODUCTGROUP":
  490.                     //print('<br>PRODUCTGROUP');
  491.                     $startText substr($text2Parse0$right+1);
  492.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getProductGroup($elementId$request), $startText);
  493.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  494.                     $restContentParsed $this->parseContent($request$restContent);
  495.                     $parsedText $startTextParsed.$restContentParsed;
  496.                     break; //case "PRODUCTGROUP":      
  497.                 case "WEBGALLERIES":
  498.                     //print('<br>qqw WEBGALLERIES');
  499.                     $startText substr($text2Parse0$right+1);
  500.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getWebGalleries($elementId$request), $startText);
  501.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  502.                     $restContentParsed $this->parseContent($request$restContent);
  503.                     $parsedText $startTextParsed.$restContentParsed;
  504.                     break; //case "WEBGALLERIES":         
  505.                 case "GALLERY3D":
  506.                     //print('<br>qqw GALLERY3D');
  507.                     $startText substr($text2Parse0$right+1);
  508.                     $startTextParsed preg_replace ("{{".$parseElement."}}"$this->getGallery3D($elementId$request), $startText);
  509.                     $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  510.                     $restContentParsed $this->parseContent($request$restContent);
  511.                     $parsedText $startTextParsed.$restContentParsed;
  512.                     break; //case "GALLERY3D":                               
  513.             }
  514.             //we try to search in the rest of the content
  515.             $restContent substr($text2Parse$right+1strlen($text2Parse)-$right);
  516.             //print('<br><br><b>RESTCONTENT:</b> '.htmlentities($restContent));
  517.             //$parsedText .= $this->parseContent($request, $restContent);
  518.         }
  519.         if($parsedText == ''$parsedText $text2Parse;
  520.         return $parsedText;
  521.     }
  522.     function getRedactionList(Request $request$redactionListId) {
  523.         $session $request->getSession();
  524.         $listContent '';
  525.         /* we load entity managers */
  526.         $em $this->doctrine->getManager();
  527.         $dem $this->doctrine->getManager('dynamic_em');
  528.         // we get the redaction list
  529.         $redactionList $dem->getRepository(RedactionList::class)->getRedactionList($redactionListId);
  530.         if(empty($redactionList)) {
  531.             return $listContent;
  532.         }
  533.         // we get the user info
  534.         $user $em->getRepository(User::class)->getUser($redactionList->getUserId());
  535.         $userDirs $this->getUserFolderPathsFromUserId($redactionList->getUserId());
  536.         if(!empty($redactionList->getCssClass())) {
  537.             $cssClass $redactionList->getCssClass();
  538.         } else {
  539.             $cssClass '';
  540.         }
  541.         $webPages = [];
  542.         foreach($redactionList->getWebPages() as $webPage) {
  543.             $webPages[] = $webPage;
  544.         }
  545.         foreach(array_reverse($webPages) as $webPage) {
  546.             $listContent .= '<div class="'.$cssClass.'redactionListPage">';
  547.             $listContent .= '<div class="'.$cssClass.'redactionListThumb">';
  548.             //print('<br>QQW webPage: ');
  549.             //\Doctrine\Common\Util\Debug::dump($webPage);
  550.             //print('<br>QQW session langKey: '.$session->get('lang')->getLangKey());
  551.             $webPage->setLocale($session->get('lang')->getLangKey());
  552.             $dem->refresh($webPage);
  553.             $pageContent $webPage->getWebPageContent();
  554.             //print('<hr>QQW webPage 2: ');
  555.             //\Doctrine\Common\Util\Debug::dump($webPage);
  556.             $webPageLink $userDirs['webroot'].'/web/'.$webPage->getWebsiteId().'/page/'.$webPage->getWebPageId();
  557.             if(!empty($webPage->getImageFile())) {
  558.                 //$imagePath = 'users/'.$user->getUserName().'/images/'.$webPage->getImageFile();
  559.                 $imagePath $userDirs['web'].'/images/'.$webPage->getImageFile();
  560.                 if(!empty($redactionList->getThumbWidth())) {
  561.                     $imageWidth $redactionList->getThumbWidth();
  562.                 } else {
  563.                     $imageWidth 200;
  564.                 }
  565.                 //$listContent .= 'QQW THUMB: '.$imagePath.'</div>';
  566.                 $listContent .= '<a href="'.$webPageLink.'">';
  567.                 $listContent .= '<img src="'.$imagePath.'" width="'.$imageWidth.'" class="'.$redactionList->getThumbWidth().'">';
  568.                 $listContent .= '</a>';
  569.             }
  570.             $listContent .= '</div>';
  571.             $listContent .= '<div class="'.$cssClass.'redactionListText">';
  572.             $listContent .= '<a href="'.$webPageLink.'" class="'.$cssClass.'redactionListLink">'.$webPage->getWebPageName().'</a>';
  573.             $listContent .= '<div class="'.$cssClass.'redactionListDescription">'.$webPage->getWebPageDescription().'</div>';
  574.             $listContent .= '</div>';
  575.             $listContent .= '</div>';
  576.         }
  577.         return $listContent;
  578.     }
  579.     function getProductSelectionGuide($guideId) {
  580.         /* we load entity managers */
  581.         $em $this->doctrine->getManager();
  582.         $dem $this->doctrine->getManager('dynamic_em');
  583.         $content '';
  584.         //print('<hr>qqw Product Selection Guide ');
  585.         /* we get the selection guide */
  586.         $guide $dem->getRepository(ProductSelectionGuide::class)->getProductSelectionGuide($guideId);
  587.         /* we get product selection guide steps*/
  588.         $productSelectionStepList $dem->getRepository(ProductSelectionStep::class)->getProductSelectionStepListByGuide($guide);
  589.         /* we get the user info */
  590.         $user $em->getRepository(User::class)->getUser($guide->getUserId());
  591.         $count 0;
  592.         $content .= '<div class="productSelectionGuide">';
  593.         /* we display selection steps */
  594.         foreach($productSelectionStepList as $step) {
  595.             $count++;
  596.             $content .= '<div class="productSelectionStep">';
  597.             $content .= '<div class="productSelectionStepTitle">';
  598.             $content .= $step->getProductSelectionStepName();
  599.             $content .= '</div>';
  600.             $content .= '<div class="productSelectionStepContent">';
  601.             /* we display parameters */
  602.             foreach($step->getParameters() as $parameter) {
  603.                 $content .= '<div class="productSelectionParameter">';
  604.                 $paramName 'param_'.$parameter->getProductParameterId();
  605.                 if($parameter->getParameterType() == 1) {
  606.                     /* we display choices */
  607.                     $choices $parameter->getProductParameterChoices();
  608.                     $pChoices explode(";"$parameter->getProductParameterChoices());
  609.                     $choiceCount 0;
  610.                     foreach($pChoices as $choice) {
  611.                         $choiceCount++;
  612.                         $content .= '<label for="'.$paramName.'_'.$choiceCount.'" class="guideChoice"><input type="radio" name="'.$paramName.'" id="'.$paramName.'_'.$choiceCount.'" value="'.trim($choice).'"><span class="guideChoiceTitle">'.trim($choice).'</span></label>';
  613.                     }
  614.                 } else {
  615.                     /* we display checkboxes */
  616.                     //$content .= $parameter->getProductParameterName();
  617.                     $content .= '<label for="'.$paramName.'" class="guideChoice"><input type="checkbox" name="'.$paramName.'" id="'.$paramName.'" value="1"><span class="guideChoiceTitle">'.$parameter->getProductParameterName().'</span></label>';
  618.                 }
  619.                 $content .= '</div>';
  620.             }
  621.             $content .= '</div>';
  622.             $content .= '</div>';
  623.         }
  624.         $content .= '</div>';
  625.         return $content;
  626.     }
  627.     function getProductGroup($groupIdRequest $request) {
  628.         /* we load session data */
  629.         //parent::init($request); 
  630.         $session $request->getSession();
  631.         /* we load entity managers */
  632.         $em $this->doctrine->getManager();
  633.         $dem $this->doctrine->getManager('dynamic_em');
  634.         $eshopId null;
  635.         $content '';
  636.         $userDirs $this->getUserFolderPaths($request);
  637.         /* we get the product group */
  638.         $group $dem->getRepository(ProductGroup::class)->getProductGroup($groupId);
  639.         /* we get products */
  640.         $productCollection $dem->getRepository(Product::class)->getProductListByGroup($group);
  641.         //print('<br>qqw request: ');
  642.         //\Doctrine\Common\Util\Debug::dump($request);
  643.         $productThumbs = array();
  644.         foreach($productCollection as $product) {
  645.             $pId $product->getProductId();
  646.             if(empty($eshopId)) {
  647.                 $eshopId $dem->getRepository(Product::class)->getEshopByProduct($product->getProductId());
  648.                 if(empty($eshopId)) {
  649.                     //we get ehop id from url
  650.                     $pathArray explode("/"$request->getPathInfo());
  651.                     $eshopId $pathArray[2];
  652.                 }
  653.                 $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  654.                 $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  655.             }
  656.             if($product->getImage1() != "") {
  657.                 if (strpos($product->getImage1(), 'http') === false) {
  658.                     $imagePath 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  659.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  660.                 } else {
  661.                     $imagePath $product->getImage1();
  662.                     $path parse_url($imagePathPHP_URL_PATH);
  663.                     $imageThumbPath 'users/'.$user->getUserName().'/images/thumb_'.basename($path);
  664.                 }
  665.                 /*
  666.                 print('<br>qqw imagePath: '.$imagePath);
  667.                 print('<br>qqw imageThumbPath: '.$imageThumbPath);  
  668.                 */
  669.                 $imageThumb $this->getEshopImageThumb($eshop$imagePath$imageThumbPath);
  670.                 $productThumbs[$pId] = $imageThumb;
  671.             }
  672.         }
  673.         $content .= '<div class="productGroup">';
  674.         foreach($productCollection as $product) {
  675.             if(empty($eshopId)) {
  676.                 $eshopId $dem->getRepository(Product::class)->getEshopByProduct($product->getProductId());
  677.                 $eshop $em->getRepository(Eshop::class)->getEshop($eshopId);
  678.                 $user $em->getRepository(User::class)->getUser($eshop->getUserId());
  679.             }
  680.             /* we setup product names - if empty then we load multilingual values */
  681.             $productName '';
  682.             if(!empty($product->getProductName()) && $product->getProductName() != '') {
  683.                 $productName $product->getProductName();
  684.             } else {
  685.                 //we try to get the product name from multilangual fields 
  686.                 foreach($eshop->getLanguages() as $lang) {
  687.                     $product->setLocale($lang->getLangKey());
  688.                     $dem->refresh($product);
  689.                     if(!empty($product->getProductName()) && $product->getProductName() != '') {
  690.                         $productName $product->getProductName();
  691.                     }
  692.                 }
  693.             }
  694.             $product->setProductName($productName);
  695.             /*
  696.             print('<br>qqw eshopId: ');
  697.             \Doctrine\Common\Util\Debug::dump($eshopId);
  698.             */
  699.             $productLink $userDirs['webroot'].'/eshop/'.$eshopId.'/product/'.$product->getProductId();
  700.             /* we get price(s) to display */
  701.             $displayPrice null;
  702.             $productIds = array();
  703.             $productIds[] = $product->getProductId();
  704.             /* we load prices */
  705.             $productPriceList $dem->getRepository(Product::class)->getProductPriceList($productIds);
  706.             $priceLevelList $dem->getRepository(PriceLevel::class)->getPriceLevelList();
  707.             $defaultCurrency $em->getRepository(Currency::class)->getCurrency($eshop->getPreferredCurrencyId());
  708.             $targetCurrency $session->get('eshopCurrency');
  709.             /* we load currency rated prices */
  710.             $productPriceList $dem->getRepository(Product::class)->getCurrencyRatedProductPriceList($productPriceList$defaultCurrency$targetCurrency);
  711.             $displayPrice null;
  712.             $stoneShopPrice null;
  713.             foreach($productPriceList as $price) {
  714.                 if($price->getProductId() == $product->getProductId()) {
  715.                     /* we get default price level */
  716.                     /* we get price level according to logged contact-customer */
  717.                     if(!empty($session->get('contact')) && !empty($session->get('contact')->getPriceLevel()) && $price->getPriceLevelId()==$session->get('contact')->getPriceLevel()->getPriceLevelId()) {
  718.                         /* we get netto or brutto value according to e-shop configuration */
  719.                         if(!empty($eshop->isDisplayNettoPrices()) && $eshop->isDisplayNettoPrices()==true) {
  720.                             $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  721.                         } else {
  722.                             $displayPrice round($price->getBruttoValue(),$eshop->getRoundPrice());
  723.                         }
  724.                         if(!empty($eshop->isDisplayNettoPrices()) && $eshop->isDisplayNettoPrices()==true) {
  725.                             //$displayPriceVAT = $displayPrice + ($displayPrice * ($productVAT/100));
  726.                             //$displayPriceVATLabel = $this->translator->trans('product.price_with_VAT');
  727.                         } else {
  728.                             //$displayPriceVAT = $displayPrice - ($displayPrice * ($productVAT/100));
  729.                             //$displayPriceVATLabel = $this->translator->trans('product.price_without_VAT');
  730.                         }
  731.                     } elseif($price->getPriceLevelId() == 1) {
  732.                         /* we get netto or brutto value according to e-shop configuration */
  733.                         if(!empty($eshop->isDisplayNettoPrices()) && $eshop->isDisplayNettoPrices()==true) {
  734.                             $displayPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  735.                             $stoneShopPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  736.                         } else {
  737.                             $displayPrice round($price->getBruttoValue(),$eshop->getRoundPrice());
  738.                             $stoneShopPrice round($price->getBruttoValue(),$eshop->getRoundPrice());
  739.                         }
  740.                     } elseif ($price->getPriceLevelId() > 1) {
  741.                         foreach($priceLevelList as $priceLevel) {
  742.                             if($price->getPriceLevelId() == $priceLevel->getPriceLevelId() && $priceLevel->getPriceLevelName() == "stoneshop") {
  743.                                 if(!empty($eshop->isDisplayNettoPrices()) && $eshop->isDisplayNettoPrices()==true) {
  744.                                     $stoneShopPrice round($price->getNettoValue(),$eshop->getRoundPrice());
  745.                                 } else {
  746.                                     $stoneShopPrice round($price->getBruttoValue(),$eshop->getRoundPrice());
  747.                                 }
  748.                             }
  749.                         }
  750.                     }
  751.                 }
  752.             }
  753.             //$displayPrice = 22;         
  754.             $content .= $this->renderView('eshopProduct_GRID.html.twig',
  755.                 array('product' => $product,
  756.                     'eshop' => $eshop,
  757.                     'displayPrice' => $displayPrice,
  758.                     'stoneShopPrice' => $stoneShopPrice,
  759.                     'productThumbs' => $productThumbs,
  760.                     'userDirs' => $userDirs,
  761.                     'user' => $user)
  762.             );
  763.         }
  764.         $content .= '</div>';
  765.         /*
  766.         print('<hr>qqw content: ');
  767.             \Doctrine\Common\Util\Debug::dump($content);    
  768.         print('<hr>');
  769.         */
  770.         return $content;
  771.     }
  772.     function getWebGalleries($webIdRequest $request) {
  773.         /* we load entity managers */
  774.         $em $this->doctrine->getManager();
  775.         $dem $this->doctrine->getManager('dynamic_em');
  776.         //$rootDir = $this->container->get('kernel')->getRootDir();
  777.         /* we get current web */
  778.         $web $em->getRepository(Website::class)->getWebsite($webId);
  779.         $userDirs $this->getUserFolderPathsFromUserId($web->getUserId());
  780.         $eshopId null;
  781.         $content '';
  782.         /* we get list of galleries */
  783.         $galleryList $dem->getRepository(Gallery::class)->getWebGalleryList($webId);
  784.         //print('<br>qqw current webpage: '.$request->getUri());
  785.         /*
  786.         \Doctrine\Common\Util\Debug::dump($productCollection);
  787.         */
  788.         $content .= '<div class="galleryList">';
  789.         foreach($galleryList as $gallery) {
  790.             $content .= '<div class="galleryPanel">';
  791.             if(!empty($gallery->getGalleryLogoUrl())) {
  792.                 $content .= '<a href="'.$userDirs['webroot'].'/public/'.$web->getWebsiteId().'/gallery/'.$gallery->getGalleryId().'?backUrl='.$request->getUri().'"><img src="'.$gallery->getGalleryLogoUrl().'" alt="Gallery Logo" border="0" width="200"></a>';
  793.             }
  794.             $content .= '<div class="galleryDescription">';
  795.             $content .= '<a href="'.$userDirs['webroot'].'/public/'$webId.'/gallery/'.$gallery->getGalleryId().'?backUrl='.$request->getUri().'" class="galleryTitle">'.$gallery->getGalleryName().'</a>';
  796.             $content .= $gallery->getGalleryDescription();
  797.             $content .= '</div>';
  798.             $content .= '</div>';
  799.         }
  800.         $content .= '</div>';
  801.         return $content;
  802.     }
  803.     function getInteractiveSlideShow($galleryId) {
  804.         /* we load entity managers */
  805.         $em $this->doctrine->getManager();
  806.         $dem $this->doctrine->getManager('dynamic_em');
  807.         /* we get the gallery info */
  808.         $gallery $dem->getRepository(Gallery::class)->getGallery($galleryId);
  809.         $galleryItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galleryId);
  810.         $userDirs $this->getUserFolderPathsFromUserId($gallery->getUserId());
  811.         /*
  812.         print('<br>qqw getInteractiveSlideShow: ');
  813.         \Doctrine\Common\Util\Debug::dump($gallery);
  814.         */
  815.         $sWidth $gallery->getSlideshowWidth();
  816.         $sHeight $gallery->getSlideshowHeight();
  817.         $sCount 0;
  818.         $navPanel '';
  819.         $slideShow '<div class="slideshowPanel">';
  820.         $slideShow .= '<div id="slideshow" style="z-index:1;" class="slideshow">';
  821.         foreach($galleryItemCollection as $galleryItem) {
  822.             /*
  823.             print('<br>qqw galleryItem: ');
  824.             \Doctrine\Common\Util\Debug::dump($galleryItem);
  825.             */
  826.             /*
  827.             if(strpos($row['title'],"ttp://")>0) $img = $row['title'];
  828.             else $img = './users/'.$userName.'/gallery/'.rawurlencode($galleryName).'/'.$row['title'];
  829.             */
  830.             $img $userDirs['web']."/images/".$galleryItem->getGalleryItemFile();
  831.             //$webPath = $userDirs['web']."/images/".$galleryItem->getGalleryItemFile();
  832.             if($sCount == 0)
  833.             {
  834.                 $slideShow .= '<div class="active" id="slide_'.$sCount.'">';
  835.                 if($galleryItem->getClickURL()!=''$slideShow .= '<a href="'.$galleryItem->getClickURL().'">';
  836.                 $slideShow .= '<img src="'.$img.'" alt="Slideshow Image '.$sCount.'" class="slideshowImage" border="0" />';
  837.                 if($galleryItem->getClickURL()!=''$slideShow .= '</a>';
  838.                 $slideShow .= '</div>';
  839.             }
  840.             else
  841.             {
  842.                 $slideShow .= '<div id="slide_'.$sCount.'">';
  843.                 if($galleryItem->getClickURL()!=''$slideShow .= '<a href="'.$galleryItem->getClickURL().'">';
  844.                 $slideShow .= '<img src="'.$img.'" alt="Slideshow Image '.$sCount.'" class="slideshowImage" border="0" />';
  845.                 if($galleryItem->getClickURL()!=''$slideShow .= '</a>';
  846.                 $slideShow .= '</div>';
  847.             }
  848.             if($galleryItem->getGalleryItemName()!=''$countLabel $galleryItem->getGalleryItemName();
  849.             else $countLabel $sCount 1;
  850.             //if($sCount > 0) $navPanel .= '';
  851.             $navPanel .= '<span id="slideNumber_'.$sCount.'" class="slideNumber"><a href="javascript:void(0)" onclick="viewFadeSlide('.$sCount.', '.count($galleryItemCollection).')" class="slideLink">'.$countLabel.'</a></span>';
  852.             $sCount++;
  853.         }
  854.         $slideShow .= '</div>';
  855.         $slideShow .= '</div>';
  856.         $slideShow .= '<div class="slideMenu">'.$navPanel.'</div>';
  857.         //$slideShow .= '<table border="0" cellpadding="0" cellspacing="0" align="center"><tr><td align="center" valign="top" class="slideLabelTable">'.$navPanel.'</td></tr></table>';
  858.         return $slideShow;
  859.     }
  860.     function getGallery3D($gallery3DIdRequest $request) {
  861.         /* we load session data */
  862.         //parent::init($request); 
  863.         $session $request->getSession();
  864.         // we load entity managers
  865.         $em $this->doctrine->getManager();
  866.         $dem $this->doctrine->getManager('dynamic_em');
  867.         $content '';
  868.         // we get the gallery
  869.         $gallery3D $dem->getRepository(Gallery3D::class)->getGallery3D($gallery3DId);
  870.         $user $em->getRepository(User::class)->getUser($gallery3D->getUserId());
  871.         $userDirs $this->getUserFolderPaths($request$user->getUserName());
  872.         $logger $this->getLogger(null'gallery 3D: '.$gallery3DId);
  873.         //print('<br>gallery3D: ');
  874.         //\Doctrine\Common\Util\Debug::dump($gallery3D);  
  875.         // we get parent gallery items
  876.         $galleryItemCollection null;
  877.         if(!empty($gallery3D->getGallery())) {
  878.             $galId $gallery3D->getGallery()->getGalleryId();
  879.             $galleryItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  880.         }
  881.         // we get parent gallery items
  882.         $textureItemCollection null;
  883.         if(!empty($gallery3D->getTextureGallery())) {
  884.             $galId $gallery3D->getTextureGallery()->getGalleryId();
  885.             $textureItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  886.         }
  887.         // print('<br>user: ');
  888.         // \Doctrine\Common\Util\Debug::dump($user);         
  889.         // print('<br>QQW freeWorld 22');
  890.         // \Doctrine\Common\Util\Debug::dump($gallery3D->getFreeWorlds());            
  891.         $content .= '<div class="gallery3DPanel">';
  892.         $template3D 'gallery3D/gallery3D.html.twig';
  893.         if(!empty($gallery3D->getTemplate3DPath())) {
  894.             $template3D 'gallery3D/'.$gallery3D->getTemplate3DPath();
  895.         }
  896.         //print('<hr>qqw template3D: '.$template3D);
  897.         $content .= $this->renderView($template3D,
  898.             array('gallery3D' => $gallery3D,
  899.                 'user' => $user,
  900.                 'userDirs' => $userDirs,
  901.                 'logger' => $logger,
  902.                 'galleryItemCollection' => $galleryItemCollection,
  903.                 'textureItemCollection' => $textureItemCollection,
  904.                 'isHeader' => false,
  905.                 'isFullscreen' => false,
  906.             )
  907.         );
  908.         $content .= '</div>';
  909.         /*
  910.         print('<hr>qqw content: ');
  911.             \Doctrine\Common\Util\Debug::dump($content);    
  912.         print('<hr>');
  913.         */
  914.         return $content;
  915.     }
  916.     function GetImage($path) {
  917.         //$mime = mime_content_type($path);
  918.         $mime = @exif_imagetype($path);
  919.         //print('<br>qqw mime: '.$mime);
  920.         switch($mime) {
  921.             case 'IMAGETYPE_PNG':
  922.             case 3:
  923.                 $img imagecreatefrompng($path);
  924.                 break;
  925.             case 'IMAGETYPE_GIF':
  926.             case 1:
  927.                 $img imagecreatefromgif($path);
  928.                 break;
  929.             case 'IMAGETYPE_JPEG':
  930.             case 2:
  931.                 $img imagecreatefromjpeg($path);
  932.                 break;
  933.             case 'IMAGETYPE_BMP':
  934.             case 6:
  935.                 $img imagecreatefrombmp($path);
  936.                 break;
  937.             default:
  938.                 $img null;
  939.         }
  940.         /*
  941.         print('<br>qqw img: ');
  942.         \Doctrine\Common\Util\Debug::dump($img);
  943.         */
  944.         return $img;
  945.     }
  946.     function analyseImageFromText($text=""$maxCharacterRow=50) {
  947.         $analysedText = array();
  948.         return $analysedText;
  949.     }
  950.     function getImageFromText($text=""$colorType="default"$imagePath$imageWebPath$countCharactersInLine 30$imageName="image_name"$imageWidth=400$imageHeight=60$fontSize=40$positionY 40) {
  951.         /* Set the content-type */
  952.         //header('Content-type: image/png');
  953.         $newText wordwrap($text$countCharactersInLine"\n"false);
  954.         $arrayText explode("\n"$newText);
  955.         $rowCount count($arrayText);
  956.         //print('<br>QQW rowcount: '.$rowCount);
  957.         //print('<br>QQW new image text: '.$newText);
  958.         //print('<br>QQW imageWidth: '.$imageWidth);
  959.         //print('<br>QQW imageHeight: '.$imageHeight);
  960.         if($rowCount 0) {
  961.             $imageHeight $imageHeight $rowCount;
  962.         }
  963.         /* Create the image */
  964.         $im imagecreatetruecolor($imageWidth$imageHeight);
  965.         /* Create some colors */
  966.         $white imagecolorallocate($im255255255);
  967.         $grey imagecolorallocate($im128128128);
  968.         $silver imagecolorallocate($im177177177);
  969.         $black imagecolorallocate($im000);
  970.         $green imagecolorallocate($im02550);
  971.         $yellow imagecolorallocate($im2552550);
  972.         $orange imagecolorallocate($im2551500);
  973.         switch ($colorType) {
  974.             case "default":
  975.                 $bgColor $black;
  976.                 $textColor $yellow;
  977.                 break;
  978.             case "silver-black":
  979.                 $bgColor $silver;
  980.                 $textColor $black;
  981.                 break;
  982.             case "black-yellow":
  983.                 $bgColor $black;
  984.                 $textColor $yellow;
  985.                 break;
  986.             case "black-white":
  987.                 $bgColor $white;
  988.                 $textColor $black;
  989.                 break;
  990.             case "black-green":
  991.                 $bgColor $black;
  992.                 $textColor $green;
  993.                 break;
  994.             case "orange-black":
  995.                 $bgColor $black;
  996.                 $textColor $orange;
  997.                 break;
  998.         }
  999.         imagefilledrectangle($im00, ($imageWidth-1), ($imageHeight-1), $bgColor);
  1000.         /* font path */
  1001.         //$font = 'arial.ttf';
  1002.         //$font = "../web/ArialBold.ttf";
  1003. //        $font = $this->get('kernel')->getRootDir().'/public/ArialBold.ttf';
  1004.         $font $this->appKernel->getProjectDir() . '/public/ArialBold.ttf';
  1005.         //$font = "ArialBold.ttf";
  1006.         //$font = "http://localhost/alliancemarkets2/web/ArialBold.ttf";
  1007.         /* Add some shadow to the text */
  1008.         //imagettftext($im, 40, 0, 40, 50, $black, $font, $text);
  1009.         /* Add the text */
  1010.         //$positionY = 30;
  1011.         foreach($arrayText as $key => $rowText) {
  1012.             //print('<br>QQW new text row: '.$rowText);
  1013.             imagettftext($im$fontSize015$positionY$textColor$font$rowText);
  1014.             $positionY += 25;
  1015.         }
  1016.         /* Using imagepng() results in clearer text compared with imagejpeg() */
  1017.         $file $imagePath."/".$imageName.".png";
  1018.         $fileWeb $imageWebPath."/".$imageName.".png";
  1019.         imagepng($im$file);
  1020.         //imagejpeg($im, $file);
  1021.         imagedestroy($im);
  1022.         return $fileWeb;
  1023.     }
  1024.     function getNormalisedText($text="") {
  1025.         $text str_replace(' '''$text);
  1026.         $text str_replace('.'''$text);
  1027.         $text str_replace("'"""$text);
  1028.         return $text;
  1029.     }
  1030.     function getEshopImageThumb($eshop$imagePath$imageThumbPath$isCategoryThumb false$category null) {
  1031.         if(!is_file($imageThumbPath)) {
  1032.             //$imageData = getimagesize($imagePath);
  1033.             list($width$height) = @getimagesize($imagePath);
  1034.             if($width 0)
  1035.             {
  1036.                 $imageData2 = array('h' => $height'w' => $width );
  1037.                 if(!empty($isCategoryThumb) && $isCategoryThumb) {
  1038.                     //getEshopImageThumb
  1039.                     if(!empty($eshop->getCategoryImageThumbWidth()) && $eshop->getCategoryImageThumbWidth() > 0) {
  1040.                         $thumbWidth $eshop->getCategoryImageThumbWidth();
  1041.                     } else {
  1042.                         $thumbWidth 150;
  1043.                     }
  1044.                 } elseif(!empty($category) && !empty($category->getImageThumbWidth()) && $category->getImageThumbWidth() > 0) {
  1045.                     $thumbWidth $category->getImageThumbWidth();
  1046.                 } else {
  1047.                     $thumbWidth $eshop->getImageThumbWidth();
  1048.                 }
  1049.                 if($imageData2['w'] == 0$imageData2['w'] = 1;
  1050.                 $thumbHeight = ($imageData2['h']/$imageData2['w'])*$thumbWidth;
  1051.                 if(!empty($category) && !empty($category->getImageThumbHeight()) && $category->getImageThumbHeight() > 0) {
  1052.                     $eshopThumbHeight $category->getImageThumbWidth();
  1053.                 } elseif($eshop->getImageThumbHeight() > 0) {
  1054.                     $eshopThumbHeight $eshop->getImageThumbHeight();
  1055.                 }  else {
  1056.                     $eshopThumbHeight 200;
  1057.                 }
  1058.                 /* if the thumb height is bigger than allowed thumb height we generate thumb according to height*/
  1059.                 if($thumbHeight $eshopThumbHeight) {
  1060.                     $thumbHeight $eshopThumbHeight;
  1061.                     if($imageData2['h'] == 0$imageData2['h'] = 1;
  1062.                     $thumbWidth = ($imageData2['w']/$imageData2['h'])*$thumbHeight;
  1063.                 }
  1064.                 //print('<br>qqw thumb w: '.$thumbWidth.' h: '.$thumbHeight);
  1065.                 $srcimg $this->GetImage($imagePath);
  1066.                 $destimg = @imagecreatetruecolor($thumbWidth,$thumbHeight);
  1067.                 /*
  1068.                 print('<br>qqw srcimg: ');
  1069.                 print_r($srcimg);
  1070.                 */
  1071.                 /*
  1072.                 if(@getimagesize($imagePath)) {
  1073.                     //print('<br>qqw is file: '.$imagePath);
  1074.                     ImageCopyResized($destimg,$srcimg,0,0,0,0,$thumbWidth,$thumbHeight,ImageSX($srcimg),ImageSY($srcimg));
  1075.                     ImageJPEG($destimg,$imageThumbPath, 100);
  1076.                 }
  1077.                 */
  1078.             }
  1079.         }
  1080.         return $imageThumbPath;
  1081.     }
  1082.     function getLogger($user=null$loggerName 'universal') {
  1083.         $logPaths = array();
  1084.         $rootDir $this->appKernel->getProjectDir();
  1085.         //$templatesDir = $this->appKernel->getProjectDir() . '/app/Resources/views';
  1086. //        $rootDir = $this->container->get('kernel')->getRootDir();
  1087.         if(!empty($user)) {
  1088.             /* we get user paths */
  1089.             //@todo - setting for users
  1090.         } else {
  1091.             /* we set logging to universal location */
  1092.             $logPaths['logPath'] = $rootDir.'/var/log/am2.log';
  1093.             $logPaths['logErrorPath'] = $rootDir.'/var/log/am2_error.log';
  1094.         }
  1095.         /*
  1096.         print("\n\n qqw logPaths: ");
  1097.         \Doctrine\Common\Util\Debug::dump($logPaths);
  1098.         */
  1099.         $logger = new Logger($loggerName);
  1100.         //$log = $this->container->get('logger');
  1101.         $errorHandler = new ErrorHandler($logger);
  1102.         $errorHandler->registerErrorHandler([], false);
  1103.         $errorHandler->registerExceptionHandler();
  1104.         $errorHandler->registerFatalHandler();
  1105.         if(!empty($logPaths['logPath'])) {
  1106.             $logHandler = new StreamHandler($logPaths['logPath'], Logger::NOTICE);
  1107.             $logger->pushHandler($logHandler);
  1108.         }
  1109.         //$logError= new Logger('files');
  1110.         if(!empty($logPaths['logErrorPath'])) {
  1111.             $logErrorHandler = new StreamHandler($logPaths['logErrorPath'], Logger::ERROR);
  1112.             $logger->pushHandler($logErrorHandler);
  1113.             //$syslogHandler = new SyslogHandler($logPaths['logErrorPath'], 'user');
  1114.             //$log->pushHandler($syslogHandler);
  1115.         }
  1116.         return $logger;
  1117.     }
  1118.     function readFileTail($file$lines) {
  1119.         //global $fsize;
  1120.         $handle fopen($file"r");
  1121.         $linecounter $lines;
  1122.         $pos = -2;
  1123.         $beginning false;
  1124.         $text = array();
  1125.         while ($linecounter 0) {
  1126.             $t " ";
  1127.             while ($t != "\n") {
  1128.                 if(fseek($handle$posSEEK_END) == -1) {
  1129.                     $beginning true;
  1130.                     break;
  1131.                 }
  1132.                 $t fgetc($handle);
  1133.                 $pos --;
  1134.             }
  1135.             $linecounter --;
  1136.             if ($beginning) {
  1137.                 rewind($handle);
  1138.             }
  1139.             $text[$lines-$linecounter-1] = fgets($handle);
  1140.             if ($beginning) break;
  1141.         }
  1142.         fclose ($handle);
  1143.         return array_reverse($text);
  1144.     }
  1145.     function is_url($url) {
  1146.         $file_headers = @get_headers($url);
  1147.         if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
  1148.             return false;
  1149.         }
  1150.         else {
  1151.             return true;
  1152.         }
  1153.     }
  1154.     /**
  1155.      * Returns generated unique ID.
  1156.      *
  1157.      * @return string
  1158.      */
  1159.     public function generateUId()
  1160.     {
  1161.         //$this->container
  1162.         $session $this->container->get('session');
  1163.         return substr$session->getId(), 0) . substrmd5uniqid''true ).'|'.microtime() ), 029 );
  1164.     }
  1165.     function translate2($from_lan$to_lan$text){
  1166.         $json json_decode(file_get_contents('https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' urlencode($text) . '&langpair=' $from_lan '|' $to_lan));
  1167.         $translated_text $json->responseData->translatedText;
  1168.         return $translated_text;
  1169.     }
  1170.     function translate($from_lan$to_lan$text) {
  1171.         $url $this->translateBaseUrl '?key=' $this->translateApiKey '&text=' rawurlencode($text) . '&lang=' $from_lan '-' $to_lan;
  1172.         $handle curl_init($url);
  1173.         curl_setopt($handleCURLOPT_SSL_VERIFYPEERFALSE);
  1174.         curl_setopt($handleCURLOPT_SSL_VERIFYHOSTFALSE);
  1175.         curl_setopt($handleCURLOPT_RETURNTRANSFERtrue);
  1176.         $response curl_exec($handle);
  1177.         $responseDecoded json_decode($responsetrue);
  1178.         curl_close($handle);
  1179.         //print("<br>QQW responseDecoded: ");
  1180.         //\Doctrine\Common\Util\Debug::dump($responseDecoded);
  1181.         if(!empty($responseDecoded['text'])) {
  1182.             $translated_text $responseDecoded['text'][0];
  1183.         } else {
  1184.             $translated_text '';
  1185.         }
  1186.         return $translated_text;
  1187.     }
  1188.     /**
  1189.      * Checks if any user is logged in admin.
  1190.      *
  1191.      * @return string
  1192.      */
  1193.     public function isLoggedUser($request$loginRedirect true) {
  1194.         $this->init($request);
  1195.         $session $request->getSession();
  1196.         if(!empty($session->get('user'))) {
  1197.             return true;
  1198.         } else {
  1199.             return false;
  1200.         }
  1201.     }
  1202.     # get success response from recaptcha and return it to controller
  1203.     function captchaVerify($recaptcha) {
  1204.         $url "https://www.google.com/recaptcha/api/siteverify";
  1205.         $ch curl_init();
  1206.         curl_setopt($chCURLOPT_URL$url);
  1207.         curl_setopt($chCURLOPT_HEADER0);
  1208.         curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
  1209.         curl_setopt($chCURLOPT_POSTtrue);
  1210.         curl_setopt($chCURLOPT_POSTFIELDS, array(
  1211.             "secret"=>"6LdD38wZAAAAAPUXf4e2LKQ49KaKKdrrEmKhyAEn","response"=>$recaptcha));
  1212.         $response curl_exec($ch);
  1213.         curl_close($ch);
  1214.         $data json_decode($response);
  1215.         return $data->success;
  1216.     }
  1217.     public function getTotalOrderItemPrice(Request $request$product$units$isPackSaleModule=false)
  1218.     {
  1219.         $totalOrderItemPrice = (int)$units * (int)$request->request->get('productPrice');
  1220.         if($isPackSaleModule) {
  1221.             /* @todo - product pack price*/
  1222.             //print("<br>qqw adding to basket pid: ".$product->getProductId()); 
  1223.             //print(":: units: ".$units." :: PiecesInPack:".$product->getPiecesInPack());    
  1224.             //print(":: productPrice: ".$request->request->get('productPrice'));   
  1225.             if($product->getPiecesInPack() > && ($units $product->getPiecesInPack()) > 1) {
  1226.                 //print('<br>... more that 10');
  1227.                 //price for package(s)
  1228.                 $subPrice1 floor($units $product->getPiecesInPack()) * $request->request->get('productPackPrice');
  1229.                 //print(' :: subPrice1: '.$subPrice1);
  1230.                 //price for products left by modulo
  1231.                 $subPrice2 = ($units $product->getPiecesInPack()) * $request->request->get('productPrice');
  1232.                 //print(' :: subPrice2: '.$subPrice2);
  1233.                 $totalOrderItemPrice $subPrice1 $subPrice2;
  1234.             } elseif ($product->getPiecesInPack() > && ($units $product->getPiecesInPack()) == 1) {
  1235.                 //print('<br>... equals 10');
  1236.                 $totalOrderItemPrice floor($units $product->getPiecesInPack()) * $request->request->get('productPackPrice');
  1237.             } else {
  1238.                 //print('<br>... less that 10');
  1239.                 $totalOrderItemPrice = (int)$units * (int)$request->request->get('productPrice');
  1240.             }
  1241.             /*
  1242.             print(":: productPackPrice: ".$request->request->get('productPackPrice'));     
  1243.             echo ("<br> units mod PiecesInPack: ".($units % $product->getPiecesInPack()));                 
  1244.             echo (":: units divided PiecesInPack: ".($units / $product->getPiecesInPack()));   
  1245.             echo (":: floor: ".floor($units / $product->getPiecesInPack()));   
  1246.             */
  1247.         }
  1248.         return $totalOrderItemPrice;
  1249.     }
  1250.     public function sendEmail($to$subject$from$body)
  1251.     {
  1252.  
  1253.         $user 'info@virtualrealitycommerce.cz';
  1254.         $pass 'S7E3E4j4!f7';
  1255.         $server 'smtp.web4u.cz';
  1256.         //$port = '587';        
  1257.         $port '465';   
  1258.         // Generate connection configuration
  1259.         $dsn "smtp://" $user ":" $pass "@" $server ":" $port;
  1260.         $transport Transport::fromDsn($dsn);
  1261.         $customMailer = new Mailer($transport);
  1262.         // Generates the email
  1263.         $email = (new TemplatedEmail())
  1264.             ->from(new Address('info@virtualrealitycommerce.cz'$subject))
  1265.             ->to($to)
  1266.             ->subject($subject)
  1267.             ->htmlTemplate('emails/email.html.twig')
  1268.             ->context(['body' => $body]);
  1269.         // IMPORTANT: as you are using a customized mailer instance, you have to make the following
  1270.         // configuration as indicated in https://github.com/symfony/symfony/issues/35990.
  1271.         $loader = new FilesystemLoader('../templates/');
  1272.         $twigEnv = new Environment($loader);
  1273.         $twigBodyRenderer = new BodyRenderer($twigEnv);
  1274.         $twigBodyRenderer->render($email);
  1275.         // Sends the email
  1276.         try {
  1277.             $customMailer->send($email);
  1278.             return true;
  1279.         } catch (\Exception $e) {
  1280.             print('<br>email error: ');
  1281.             print_r($e->getMessage());
  1282.             return false;
  1283.         } 
  1284.     }
  1285.     public function sendEmail2($to$subject$from$body)
  1286.     {
  1287.         print('<br>Sending mail...');
  1288.         $body 'my email body';
  1289.         $message "<html><body><h1>" "Hi, there 99!" "</h1></body></html>";
  1290.         $headers 'MIME-Version: 1.0' "\r\n";
  1291.         $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
  1292.         $headers .= "From: Info<user@example.com>" "\r\n";
  1293.         $status = @mail("webexciter@yahoo.com""Testing"$message$headers);  
  1294.         print('<br>mail status:');
  1295.         print_r($status);
  1296.         $headers  "MIME-Version: 1.0\r\n";
  1297.                 $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  1298.                 $headers .= "From: <{$from}>\r\n";
  1299.                 $headers .= "Reply-To: <{$from}>\r\n";
  1300.                 $headers .= "Subject: {$subject}\r\n";
  1301.                 $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  1302.         mail('webexciter@yahoo.com''My Subject''My Message');        
  1303.         if(mail($to$subject$body$headers)) {
  1304.                     print('<br>Email was sent.');
  1305.                     print('<br>QQW Sending 2');
  1306.             return true;
  1307.         } else {
  1308.             print('<br>Email was not sent.');
  1309.             print_r(error_get_last());
  1310.             return false;
  1311.         }      
  1312.     }
  1313.     public function sendEmail3($to$subject$from$body)
  1314.     {
  1315.         print('<br>Sending Symfony mailer...');
  1316.         $email = (new Email())
  1317.             ->from('info@virtualrealitycommerce.cz')
  1318.             //->from($user->getEmail())
  1319.             ->to($to)
  1320.             //->cc('cc@example.com')
  1321.             //->bcc('bcc@example.com')
  1322.             //->replyTo('fabien@example.com')
  1323.             //->priority(Email::PRIORITY_HIGH)
  1324.             ->subject('Time for Symfony Mailer 101 !')
  1325.             ->text('Sending emails is fun again!')
  1326.             ->html('<p>See Twig integration for better HTML integration!</p>');
  1327.         try {
  1328.             $this->mailer->send($email);
  1329.             //$this->addFlash('notice', $this->translator->trans('user.forgotten_password_sent').': '.$emailAddress);
  1330.             return true;
  1331.         } catch (\Exception $e) {
  1332.             // some error prevented the email sending; display an
  1333.             // error message or try to resend the message
  1334.             //$this->addFlash('error', $this->translator->trans('user.forgotten_password_sent_error').': '.$emailAddress);
  1335.             print_r($e->getMessage());
  1336.             return false;
  1337.         }       
  1338.     }
  1339.     public function sendEmail4($to$subject$from$body)
  1340.     {
  1341.         print('<br>Sending cli email...'.$body);
  1342.         $output null;
  1343.         $retval null;
  1344.         $body "<h1>my email title</h1>";
  1345.         //$command = 'echo "'.addslashes($body).'" | mail -a "Content-type: text/html" -s "'.$subject.'" '.$to;
  1346.         $command 'echo "'.$body.'" | mail -s "'.$subject.'" '.$to;
  1347.         if (exec($command$output$retval) === false) {
  1348.             var_dump($output);
  1349.             return false;
  1350.         } else {
  1351.             return true;
  1352.         }
  1353.         
  1354.     } 
  1355.     public function sendEmail5($to$subject$from$body)
  1356.     {
  1357.         print('<br>Sending cli email...'.$body);
  1358.         require_once("Mail.php");
  1359.         $from "Your Name <email@blahblah.com>";
  1360.         $to "Their Name <webexcietr@yahoo.com>";
  1361.         $subject "Subject";
  1362.         $body "Lorem ipsum dolor sit amet, consectetur adipiscing elit...";
  1363.         $host "mailserver.virtualrealitycommerce.org";
  1364.         $username "smtp_username";
  1365.         $password "smtp_password";
  1366.         $headers = array('From' => $from'To' => $to'Subject' => $subject);
  1367.         $smtp Mail::factory('smtp', array ('host' => $host,
  1368.                                              'auth' => true,
  1369.                                              'username' => $username,
  1370.                                              'password' => $password));
  1371.         $mail $smtp->send($to$headers$body);
  1372.         if ( PEAR::isError($mail) ) {
  1373.             echo("<p>Error sending mail:<br/>" $mail->getMessage() . "</p>");
  1374.         } else {
  1375.             echo("<p>Message sent.</p>");
  1376.         }
  1377.         
  1378.     }
  1379.     public function sendAdminEmail($subject$from$body)
  1380.     {
  1381.         //print('<br>Sending admin email...');
  1382.         //sends email to owner
  1383.         $message = (new \Swift_Message($subject))
  1384.             ->setFrom($from)
  1385.             ->setTo('easycommerc@gmail.com')
  1386.             ->setBody($body,'text/plain')
  1387.         ;
  1388.         $this->get('mailer')->send($message);
  1389.         $this->addFlash('notice''Email was sent to administrators.');
  1390.     }
  1391.     public function adminMainMenu(Request $request)
  1392.     {
  1393.         $menuItems = array(=> array('link' => 'homeuser''langKey' => 'user.admin''routeName' => 'homeuser'),
  1394.             => array('link' => 'eshopAdmin''langKey' => 'eshop.admin''routeName' => 'eshopAdmin'),
  1395.             => array('link' => 'orderlist''langKey' => 'eshop.orders''routeName' => 'orderList'),
  1396.             => array('link' => 'productedit''langKey' => 'eshop.products''routeName' => 'productListEdit'),
  1397.             => array('link' => 'productnew''langKey' => 'eshop.new_product''routeName' => 'productNew'),
  1398.             => array('link' => 'categories''langKey' => 'eshop.categories''routeName' => 'categories'),
  1399.             => array('link' => 'categorynew''langKey' => 'eshop.new_category''routeName' => 'categoryNew'),
  1400.             => array('link' => 'contacts''langKey' => 'knowledgebase.contacts''routeName' => 'contacts'),
  1401.             => array('link' => 'eshopnew''langKey' => 'eshop.new_eshop''routeName' => 'eshopNew'),
  1402.             => array('link' => 'eshopConfig''langKey' => 'eshop.config''routeName' => 'eshopConfig'),
  1403.         );
  1404.         return $menuItems;
  1405.     }
  1406. }