vendor/uvdesk/support-center-bundle/Controller/Branding.php line 12

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\SupportCenterBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Webkul\UVDesk\SupportCenterBundle\Entity\Website;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. class Branding extends Controller
  8. {
  9.     public function theme(Request $request)
  10.     {
  11.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_ADMIN')) {
  12.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  13.         }
  14.         $errors = [];
  15.         $entityManager $this->getDoctrine()->getManager();
  16.         $settingType $request->attributes->get('type');
  17.         $userService $this->container->get('user.service');
  18.         $website $entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneBy(['code'=>"knowledgebase"]);
  19.         $configuration $entityManager->getRepository('UVDeskSupportCenterBundle:KnowledgebaseWebsite')->findOneBy(['website' => $website->getId(),'isActive' => 1]);
  20.         if ($request->getMethod() == 'POST') {
  21.             $isValid 0;
  22.             $params $request->request->all();
  23.             $parmsFile = ($request->files->get('website'));
  24.             switch($settingType) {
  25.                 case "general":
  26.                     $website->setName($params['website']['name']);
  27.                     $status array_key_exists("status",$params['website']) ? 0;
  28.                     if (isset($parmsFile['logo'])) {
  29.                         $assetDetails $this->container->get('uvdesk.core.file_system.service')->getUploadManager()->uploadFile($parmsFile['logo'], 'website');
  30.                         $website->setLogo($assetDetails['path']);
  31.                     }
  32.                     $configuration->setStatus($status);
  33.                     $configuration->setBrandColor($params['website']['brandColor']);
  34.                     $entityManager->persist($website);
  35.                     $entityManager->persist($configuration);
  36.                     $entityManager->flush();
  37.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  38.                     break;
  39.                 case "knowledgebase":
  40.                     $configuration->setPageBackgroundColor($params['website']['pageBackgroundColor']);
  41.                     $configuration->setHeaderBackgroundColor($params['website']['headerBackgroundColor']);
  42.                     $configuration->setLinkColor($params['website']['linkColor']);
  43.                     $configuration->setLinkHoverColor($params['website']['linkHoverColor']);
  44.                     $configuration->setArticleTextColor($params['website']['articleTextColor']);
  45.                     $configuration->setSiteDescription($params['website']['siteDescription']);
  46.                     $configuration->setBannerBackgroundColor($params['website']['bannerBackgroundColor']);
  47.                     $configuration->setHomepageContent($params['website']['homepageContent']);
  48.                     $removeCustomerLoginButton array_key_exists("removeCustomerLoginButton",$params['website']) ? $params['website']['removeCustomerLoginButton'] : 0;
  49.                     $removeBrandingContent array_key_exists("removeBrandingContent",$params['website']) ? $params['website']['removeBrandingContent'] : 0;
  50.                     $disableCustomerLogin array_key_exists("disableCustomerLogin",$params['website']) ? $params['website']['disableCustomerLogin'] : 0;
  51.                     $configuration->setRemoveCustomerLoginButton($removeCustomerLoginButton);
  52.                     $configuration->setRemoveBrandingContent($removeBrandingContent);
  53.                     $configuration->setDisableCustomerLogin($disableCustomerLogin);
  54.                     $ticketCreateOption array_key_exists('ticketCreateOption'$params['website']) ? 0;
  55.                     $loginRequiredToCreate array_key_exists('loginRequiredToCreate'$params['website']) ? 0;
  56.                     $configuration->setTicketCreateOption($ticketCreateOption);
  57.                     $configuration->setLoginRequiredToCreate($loginRequiredToCreate);
  58.                     $configuration->setUpdatedAt(new \DateTime());
  59.                     $entityManager->persist($configuration);
  60.                     $entityManager->flush();
  61.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  62.                     break;
  63.                 case "seo":
  64.                     $configuration->setMetaDescription($params['metaDescription']);
  65.                     $configuration->setMetaKeywords($params['metaKeywords']);
  66.                     $configuration->setUpdatedAt(new \DateTime());
  67.                     $entityManager->persist($configuration);
  68.                     $entityManager->flush();
  69.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  70.                     break;
  71.                 case "links":
  72.                     $footerLinks=[];
  73.                     $headerLinks=[];
  74.                     $headerLinks = isset($params['headerLinks'])? $params['headerLinks']: '';
  75.                     $footerLinks = isset($params['footerLinks']) ? $params['footerLinks']: 0;
  76.                     if (!empty($headerLinks)) {
  77.                         foreach ($headerLinks as $key => $link) {
  78.                             if($link['label'] == '' || $link['url'] == '' || !filter_var($link['url'], FILTER_VALIDATE_URL)) {
  79.                                 unset($headerLinks[$key]);
  80.                             }
  81.                         }
  82.                     }
  83.                     if (!empty($footerLinks)) {
  84.                         foreach ($footerLinks as $key => $link) {
  85.                             if($link['label'] == '' || $link['url'] == '' || !filter_var($link['url'], FILTER_VALIDATE_URL)) {
  86.                                 unset($footerLinks[$key]);
  87.                             }
  88.                         }
  89.                     }
  90.                     $configuration->setHeaderLinks($headerLinks);
  91.                     $configuration->setFooterLinks($footerLinks);
  92.                     $entityManager->persist($configuration);
  93.                     $entityManager->flush();
  94.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  95.                     break;
  96.                 case "broadcasting":           
  97.                     $params['broadcasting']['isActive'] = array_key_exists('isActive'$params['broadcasting']) ? true  false;
  98.                     if($params['broadcasting']['isActive']){
  99.                         $ch curl_init();
  100.                         $title 'Softguard';
  101.                         $ClearText preg_replace"/\n\s+/""\n"rtrim(html_entity_decode(strip_tags($params['broadcasting']['message']))));
  102.                         $body=$ClearText;
  103.                         $icon 'https://softguard.com/tks/public/favicon.ico';
  104.                         $to 'dmZ_pqoFTVRHsdN7u85G1L:APA91bGx9imGkHXB3pR6hbZSUv7MQOtm6M_x2-uAyufK80Wzi37JwikNlkQThddwyfC1WWqMuHkofLErr3TSmCcOpmWhAkE1VHQIZ-QaxK4v1FJQerzFzSQRlEwbiSKwmMcfs76XaH8j';
  105.                         $toAll '/topics/all';
  106.                         curl_setopt($chCURLOPT_URL'https://fcm.googleapis.com/fcm/send');
  107.                         curl_setopt($chCURLOPT_RETURNTRANSFER1);
  108.                         curl_setopt($chCURLOPT_POST1);
  109.                         curl_setopt($chCURLOPT_POSTFIELDS"{\n  \"data\": {\n    \"notification\": {\n        \"title\": \" ".$title."\",\n        \"body\": \" ".$body."\",\n        \"icon\": \" ".$icon." \",\n    }\n  },\n  \"to\": \"".$toAll."\"\n}");
  110.                         $headers = array();
  111.                         $headers[] = 'Authorization: key=AAAAowGqAko:APA91bH7GR2vHQ6HXP99sSa6s5U7t5XnDYSn_81uoQC4LxuuFGcNVTy5YSbKCRFh0PLd47B22pCCTL_h-tfOyaVIQ6joEkz4cdSSe-xuFwIl1dRye5TS2qml82k_LovpEYYcTlSVusnx';
  112.                         $headers[] = 'Content-Type: application/json';
  113.                         curl_setopt($chCURLOPT_HTTPHEADER$headers);
  114.                         $result curl_exec($ch);
  115.                         if (curl_errno($ch)) {
  116.                             echo 'Error:' curl_error($ch);
  117.                         }
  118.                         curl_close($ch);
  119.                     }
  120.                     $configuration->setBroadcastMessage(json_encode($params['broadcasting']));
  121.                     $configuration->setUpdatedAt(new \DateTime());
  122.                     $entityManager->persist($configuration);
  123.                     $entityManager->flush();
  124.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  125.                     break;
  126.                 case 'advanced':
  127.                     $configuration->setCustomCSS($request->request->get('customCSS'));
  128.                     $configuration->setScript($request->request->get('script'));
  129.                     $entityManager->persist($configuration);
  130.                     $entityManager->flush();
  131.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Branding details saved successfully.'));
  132.                     break;
  133.                 case 'time':
  134.                     $configuration->getWebsite()->setTimezone($params['form']['timezone']);
  135.                     $configuration->getWebsite()->setTimeformat($params['form']['timeFormat']);
  136.                     $entityManager->persist($configuration);
  137.                     $entityManager->flush();
  138.                     $this->addFlash('success'$this->get('translator')->trans('Success ! Time details saved successfully.'));
  139.                     break;
  140.                 default:
  141.                     break;
  142.             }
  143.         }
  144.         return $this->render('@UVDeskSupportCenter/Staff/branding.html.twig', [
  145.             'websiteData' => $website,
  146.             'type' => $settingType,
  147.             'configuration' => $configuration,
  148.             'broadcast' => json_decode($configuration->getBroadcastMessage()),
  149.         ]);
  150.     }
  151.     public function spam(Request $request)
  152.     {
  153.         if (!$this->get('user.service')->isAccessAuthorized('ROLE_ADMIN')) {
  154.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  155.         }
  156.         $entityManager $this->getDoctrine()->getManager();
  157.         $website $entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneBy(['code'=>"knowledgebase"]);
  158.         if(!$website) {
  159.             // return not found
  160.         }
  161.         $configuration $entityManager->getRepository('UVDeskSupportCenterBundle:KnowledgebaseWebsite')->findOneBy(['website' => $website->getId(), 'isActive' => 1]);
  162.         $params $request->request->all();
  163.         if ($request->getMethod() == 'POST') {
  164.             $configuration->setWhiteList($request->request->get('whiteList'));
  165.             $configuration->setBlackList($request->request->get('blackList'));
  166.             $entityManager->persist($configuration);
  167.             $entityManager->flush();
  168.             $this->addFlash('success''Spam setting saved successfully.');
  169.             return $this->redirect($this->generateUrl('helpdesk_member_knowledgebase_spam'));
  170.         }
  171.         return $this->render('@UVDeskSupportCenter/Staff/spam.html.twig', [
  172.             'whitelist'=>$configuration->getWhiteList(),
  173.             'blacklist'=>$configuration->getBlackList(),
  174.         ]);
  175.     }
  176. }