src/Twig/RCSExtension.php line 479

Open in your IDE?
  1. <?php
  2. namespace App\Twig;
  3. use Twig\Extension\AbstractExtension;
  4. use Twig\TwigFilter;
  5. use Twig\TwigFunction;
  6. use Twig\Environment;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. use Symfony\Component\Security\Core\Security;
  10. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  11. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  12. use App\Exception\ResouceNotFoundException as ResourceNotFoundException;
  13. use App\Utils\ContentHelper;
  14. use App\Utils\CategoryHelper;
  15. use App\Utils\CustomerHelper;
  16. use App\Utils\MediaHelper;
  17. use App\Utils\MenuHelper;
  18. use App\Utils\DefaultHelper;
  19. use App\Utils\PollHelper;
  20. use Symfony\Component\Form\Forms;
  21. use App\Form\DirectoryLeadType;
  22. use App\Entity\Lead;
  23. use App\Entity\Content;
  24. use App\Entity\SiteConfig;
  25. use Doctrine\Common\Collections\ArrayCollection;
  26. use \SimpleXMLElement as SimpleXMLElement;
  27. class RCSExtension extends AbstractExtension
  28. {
  29.     protected $defaultHelper;
  30.     protected $contentHelper;
  31.     protected $menuHelper;
  32.     protected $mediaHelper;
  33.     protected $categoryHelper;
  34.     protected $customerHelper;
  35.     
  36.     protected $pollHelper;
  37.     protected $twig;
  38.     protected $request;
  39.     protected $security;
  40.     
  41.     protected $container;
  42.     public function __construct (
  43.         DefaultHelper $defaultHelper,
  44.         ContentHelper $contentHelper,
  45.         MenuHelper $menuHelper,
  46.         MediaHelper $mediaHelper,
  47.         CategoryHelper $categoryHelper,
  48.         CustomerHelper $customerHelper,
  49.         PollHelper $pollHelper,
  50.         Environment $twig,
  51.         RequestStack $reqStack,
  52.         Security $security,
  53.         Container $container
  54.     ) {
  55.         $this->defaultHelper $defaultHelper;
  56.         $this->contentHelper $contentHelper;
  57.         $this->menuHelper $menuHelper;
  58.         $this->mediaHelper $mediaHelper;
  59.         $this->categoryHelper $categoryHelper;
  60.         $this->customerHelper $customerHelper;
  61.         $this->pollHelper $pollHelper;
  62.         $this->request $reqStack->getCurrentRequest();
  63.         $this->security $security;
  64.         $this->container $container;
  65.         $this->twig $twig;
  66.     }
  67.     public function getFunctions ()
  68.     {
  69.         // add custom functions below
  70.         return array (
  71.             // show_module function
  72.             new TwigFunction (
  73.                 "show_module",
  74.                 array ($this"show_module"),
  75.                 array(
  76.                     // "needs_environment" => true,
  77.                     "is_safe" => array ("html"),
  78.                 )
  79.             ),
  80.             new TwigFunction (
  81.                 "rawTwig",
  82.                 array ($this"rawTwig"),
  83.                 array(
  84.                     // "needs_environment" => true,
  85.                     "is_safe" => array ("html"),
  86.                 )
  87.             ),
  88.             // show_menu function
  89.             new TwigFunction (
  90.                 "show_menu",
  91.                 array ($this"show_menu"),
  92.                 array (
  93.                     // "needs_environment" => true,
  94.                     "is_safe" => array ("html"),
  95.                 )
  96.             ),
  97.             new TwigFunction (
  98.                 "check_modules",
  99.                 array ($this"check_modules")
  100.             ),
  101.             // get_attributes
  102.             new TwigFunction (
  103.                 "get_attributes",
  104.                 array ($this"get_attributes"),
  105.                 array (
  106.                     "is_safe" => array ("html")
  107.                 )
  108.             ),
  109.             new TwigFunction (
  110.                 "get_href",
  111.                 array ($this"get_href")
  112.             ),
  113.             new TwigFunction (
  114.                 "rcs_include",
  115.                 array ($this"rcsInclude"),
  116.                 array (
  117.                     // "needs_environment" => true
  118.                 )
  119.             ),
  120.             new TwigFunction (
  121.                 "show_media",
  122.                 array ($this"show_media")
  123.             ),
  124.             new TwigFunction (
  125.                 "post_age_format",
  126.                 array ($this"post_age_format")
  127.             ),
  128.             new TwigFunction (
  129.                 "gravity_form",
  130.                 array ($this"gravity_form")
  131.             ),
  132.             new TwigFunction (
  133.                 "get_entity",
  134.                 array ($this"get_entity")
  135.             ),
  136.             new TwigFunction (
  137.                 "unserialize",
  138.                 array ($this"unserialize")
  139.             ),
  140.             new TwigFunction (
  141.                 "from_json",
  142.                 array ($this"from_json")
  143.             )
  144.         );
  145.     }
  146.     public function from_json ($string)
  147.     {
  148.         try {
  149.             $return json_decode($stringtrue);
  150.             return $return;
  151.         } catch (\Exception $e) {
  152.         }
  153.         return [];
  154.     }
  155.     public function get_entity ($type ""$column ""$value "")
  156.     {
  157.         try {
  158.             switch ($type) {
  159.                 case "Media":
  160.                     // TODO - need to move all of these functions into helper...
  161.                     if ($column == "old_id") {
  162.                         return $this->mediaHelper->getMediaByOldId($value);
  163.                     } else if (!$value) {
  164.                         return $this->mediaHelper->getMediaById($column);
  165.                     }
  166.                     break;
  167.                 case "Content":
  168.                     if ($column == "old_id") {
  169.                         return $this->contentHelper->getContentByOldId($value);
  170.                     } else if (!$value) {
  171.                         return $this->contentHelper->getContentById($column);
  172.                     }
  173.                     break;
  174.             }
  175.         } catch (\Exception $e) {
  176.             if (get_class($e) === "App\Exception\ResourceNotFoundException") {
  177.                 return null;
  178.             }
  179.             // re-throw otherwise
  180.             throw $e;
  181.         }
  182.     }
  183.     public function unserialize ($data "")
  184.     {
  185.         return unserialize($data);
  186.     }
  187.     // hack to convert current gravity forms to default lead form
  188.     public function gravity_form ($content ""$meta = array ())
  189.     {
  190.         if (strpos($content"[gravityform") !== false) {
  191.             $buttonColor "#A41822";
  192.             if (!empty($meta["btn_color"])) {
  193.                 $buttonColor $meta["btn_color"];
  194.             }
  195.             $buttonText "Submit";
  196.             if (!empty($meta["btn_text"])) {
  197.                 $buttonText $meta["btn_text"];
  198.             }
  199.             /*
  200.             $factory = Forms::createFormFactory();
  201.             $form = $factory
  202.                 ->create(
  203.                     DirectoryLeadType::class,
  204.                     new Lead()
  205.                 )->createView();
  206.             $module = $this->show_module(array(
  207.                 "type" => "form2",
  208.                 "form" => $form,
  209.             ));
  210.             */
  211.             // for time being just create static default form
  212.             $module '
  213.                 <form method="post" class="py-4">
  214.                 <label class="btn-block"><span>First Name:</span>
  215.                     <input
  216.                         type="text"
  217.                         class="form-control"
  218.                         placeholder="Your First Name"
  219.                         name="firstname"
  220.                         required
  221.                     />
  222.                 </label>
  223.                 <label class="btn-block"><span>Last Name:</span>
  224.                     <input
  225.                         type="text"
  226.                         class="form-control"
  227.                         placeholder="Your Last Name"
  228.                         name="lastname"
  229.                         required
  230.                     />
  231.                 </label>
  232.                 <label class="btn-block"><span>Company:</span>
  233.                     <input
  234.                         type="text"
  235.                         class="form-control"
  236.                         placeholder="Your Company"
  237.                         name="company"
  238.                         required
  239.                     />
  240.                 </label>
  241.                 <label class="btn-block"><span>Phone:</span>
  242.                     <input
  243.                         type="text"
  244.                         class="form-control"
  245.                         placeholder="Your Phone"
  246.                         name="phone"
  247.                         required
  248.                     />
  249.                 </label>
  250.                 <label class="btn-block"><span>Email:</span>
  251.                     <input
  252.                         type="text"
  253.                         class="form-control"
  254.                         placeholder="Your Email Address"
  255.                         name="email"
  256.                         required
  257.                     />
  258.                 </label>
  259.                 <label class="btn-block"><span>Type of Contractor:</span></label>
  260.                 <label class="btn-block">
  261.                     <input
  262.                         type="radio"
  263.                         name="contractor_type"
  264.                         value="Primarily Residential"
  265.                         required
  266.                     />
  267.                     <span>Primarily Residential</span>
  268.                 </label>
  269.                 <label class="btn-block">
  270.                     <input
  271.                         type="radio"
  272.                         name="contractor_type"
  273.                         value="Primarily Commercial"
  274.                         required
  275.                     />
  276.                     <span>Primarily Commercial</span>
  277.                 </label>
  278.                 <label class="btn-block">
  279.                     <input
  280.                         type="radio"
  281.                         name="contractor_type"
  282.                         value="Both"
  283.                         required
  284.                     />
  285.                     <span>Both</span>
  286.                 </label>
  287.                 <label class="btn-block">
  288.                     <input
  289.                         type="radio"
  290.                         name="contractor_type"
  291.                         value="Not a Contractor"
  292.                         required
  293.                     />
  294.                     <span>Not a Contractor</span>
  295.                 </label>
  296.                 <div style="text-align: center;">
  297.                 <button
  298.                     class="btn mt-3"
  299.                     type="submit"
  300.                     style="color: #fff; background: ' $buttonColor ';"
  301.                 >' $buttonText '</button>
  302.                 </div>
  303.                 </form>
  304.             ';
  305.             // replace gravity form with default lead form
  306.             $content preg_replace("#\[gravityform[^\]]*\]#"$module$content);
  307.             $content $this->check_modules($content);
  308.         }
  309.         return $content;
  310.     }
  311.     public function check_modules ($content)
  312.     {
  313.         if (is_string($content)) {
  314.             $html $content;
  315.         } else {
  316.             $html $content->getContentFull();
  317.         }
  318.         // first replace any empty <p> tags - from wysiwyg
  319.         $html preg_replace("#<p>[^<]*\[{#""[{"$html);
  320.         $html preg_replace("#}\][^<]*</p>#""}]"$html);
  321.         // TODO - only replace modules based on author roles
  322.         // ...
  323.         // render any container elements
  324.         if (strpos($html"[{div") !== false) {
  325.             $html preg_replace_callback (
  326.                 "#\[{div(.+?)}\]#",
  327.                 array ($this"renderDiv"),
  328.                 $html
  329.             );
  330.             // add all closing tags
  331.             $html str_replace("[{/div}]""</div>"$html);
  332.         }
  333.         // render any modules
  334.         if (strpos($html"[{module") !== false) {
  335.             // render any modules included in entity content
  336.             $html preg_replace_callback (
  337.                 "#\[{module(.+?)}\]#",
  338.                 array ($this"renderModule"),
  339.                 $html
  340.             );
  341.         }
  342.         return $html;
  343.     }
  344.     public function renderDiv ($match)
  345.     {
  346.         $match $match[1];
  347.         return "<div {$match}>";
  348.     }
  349.     public function renderModule ($match)
  350.     {
  351.         // we want the attributes
  352.         $match $match[1];
  353.         $match = new SimpleXMLElement("<temp $match />");
  354.         $match current($match->attributes());
  355.         return $this->show_module($match);
  356.     }
  357.     public function show_media ($obj)
  358.     {
  359.         // TODO
  360.     }
  361.     /*
  362.      * ... pretty ugly - would be cleaner to add into the entity with a $entity->getURL() - for all content types...
  363.      *
  364.      * @param {many} $link
  365.      */
  366.     public function get_href ($link)
  367.     {
  368.         $class = \get_class($link);
  369.         $class explode("\\"$class);
  370.         $class array_pop($class);
  371.         // if content class - get the href from the content helper
  372.         if ($class == "Content") {
  373.             return $this->contentHelper->getHref($link);
  374.         }
  375.         $href "";
  376.         switch($link->getType()) {
  377.             case "content":
  378.                 // grab the content URI
  379.                 $ref $link->getRefContent();
  380.                 $href $this->contentHelper->getHrefById($ref->getId());
  381.                 break;
  382.             case "media":
  383.                 break;
  384.             case "external":
  385.                 $href $link->getRefExternal();
  386.                 break;
  387.         }
  388.         return $href;
  389.     }
  390.     public function show_module ($attrs = array())
  391.     {
  392.         if (is_string($attrs)) {
  393.             die(__FILE__.":".__LINE__." - Needs Implemented");
  394.         }
  395.         // include any used keys to prevent twig errors
  396.         $attrs array_merge(array(
  397.             "id" => "",
  398.             "slug" => "",
  399.             "type" => "",
  400.             "form" => "",
  401.             "title" => "",
  402.             "content" => "",
  403.             "position" => "",
  404.             "customer_level_or_higher" => "",
  405.         ), $attrs);
  406.         $html "";
  407.         try {
  408.             switch ($attrs["type"]) {
  409.                 case "mediagroup":
  410.                     $html $this->getMediaGroup($attrs);
  411.                     /*
  412.                     $module = $this->mediaHelper->getMediaGroupByPosition($attrs["position"]);
  413.                     $attrs["data"] = $module;
  414.                     $tmpl = $this->twig->load("elements/media-group.html.twig");
  415.                     $html = $tmpl->render(array(
  416.                         "module" =>  $attrs
  417.                         / *
  418.                         "attr" => $attrs,
  419.                         "mediagroup" => $module,
  420.                         * /
  421.                     ));
  422.                     */
  423.                     break;
  424.                 case "gallery":
  425.                     $html $this->getGallery($attrs);
  426.                     break;
  427.                 case "category":
  428.                     $attrs array_merge(array ("slug" => """length" => ""), $attrs);
  429.                     $module $this->contentHelper->getPostsByCategory($attrs["slug"], $attrs["length"]);
  430.                     $tmpl $this->twig->load("modules/category-list.html.twig");
  431.                     $html $tmpl->render(array(
  432.                         "attr" => $attrs,
  433.                         "posts" => $module,
  434.                     ));
  435.                     break;
  436.                   
  437.                     /*
  438.                 case "customer":
  439.                     $attrs = array_merge(array ("slug" => "", "length" => ""), $attrs);
  440.                     $module = $this->contentHelper->getPostsByCategory($attrs["slug"], $attrs["length"]);
  441.                     $tmpl = $this->twig->load("modules/category-list.html.twig");
  442.                     $html = $tmpl->render(array(
  443.                         "attr" => $attrs,
  444.                         "posts" => $module,
  445.                     ));
  446.                     break;
  447.                     */
  448.                 case "customers":
  449.                     $html $this->getCustomerList($attrs);
  450.                     break;
  451.                 case "title":
  452.                     $tmpl $this->twig->load("modules/module-title.html.twig");
  453.                     $html $tmpl->render(array(
  454.                         "attr" => $attrs,
  455.                     ));
  456.                     break;
  457.                 case "html":
  458.                     $tmpl $this->twig->load("modules/module-html.html.twig");
  459.                     $html $tmpl->render(array(
  460.                         "attr" => $attrs
  461.                     ));
  462.                     break;
  463.                 /*
  464.                 Do we still need these? Merge 6/12
  465.                 case "signup":
  466.                     $tmpl = $this->twig->load("modules/enews-signup-home.html.twig");
  467.                     $html = $tmpl->render();
  468.                     break;
  469.                 case "latest_classifieds":
  470.                     $tmpl = $this->twig->load("modules/latest-classifieds.html.twig");
  471.                     $html = $tmpl->render(array(
  472.                         "attr" => $attrs,
  473.                     ));
  474.                     break;
  475.                 */
  476.                 case "form":
  477.                     $attrs array_merge(array ("slug" => ""), $attrs);
  478.                     switch($attrs["slug"]) {
  479.                         case "lead":
  480.                             $tmpl $this->twig->load("forms/temp.html.twig");
  481.                             if(isset($attrs["fields"])) {
  482.                                 $html $tmpl->render(array(
  483.                                     "fields" => $attrs["fields"],
  484.                                 ));
  485.                             }
  486.                             else {
  487.                                 //should set default fields that all forms will use
  488.                                 $html $tmpl->render(array(
  489.                                     "fields" => "",
  490.                                 ));
  491.                             }
  492.                             break;
  493.                     }
  494.                     break;
  495.                 case "form2":
  496.                     $tmpl $this->twig->load("forms/default.html.twig");
  497.                     $html $tmpl->render(array(
  498.                         "module" => $attrs,
  499.                     ));
  500.                     break;
  501.                 /*
  502.                 case "signup":
  503.                     $tmpl = $this->twig->load("modules/sign-up.html.twig");
  504.                     $html = $tmpl->render(array(
  505.                         "module" => $attrs,
  506.                     ));
  507.                     break;
  508.                 case "signin":
  509.                     $tmpl = $this->twig->load("modules/sign-in.html.twig");
  510.                     $html = $tmpl->render(array(
  511.                         "module" => $attrs,
  512.                     ));
  513.                     break;
  514.                 */
  515.                 case "sign-in":
  516.                     $tmpl $this->twig->load("modules/static-sign-in.html.twig");
  517.                     $html $tmpl->render(array(
  518.                         "module" => $attrs,
  519.                     ));
  520.                     break;
  521.                 case "mobile-sign-in":
  522.                     $tmpl $this->twig->load("modules/mobile-sign-in.html.twig");
  523.                     $html $tmpl->render(array(
  524.                         "module" => $attrs,
  525.                     ));
  526.                     break;
  527.                     
  528.                 case "mobile-virus-alert":
  529.                     $tmpl $this->twig->load("modules/mobile-virus-alert.html.twig");
  530.                     $html $tmpl->render(array(
  531.                         "module" => $attrs,
  532.                     ));
  533.                     break;
  534.                 case "enews-home":
  535.                     $tmpl $this->twig->load("modules/enews-signup-home.html.twig");
  536.                     $html $tmpl->render(array(
  537.                         "module" => $attrs,
  538.                     ));
  539.                     break;
  540.                 case "enews":
  541.                     $tmpl $this->twig->load("modules/enews-signup.html.twig");
  542.                     $html $tmpl->render(array(
  543.                         "module" => $attrs,
  544.                     ));
  545.                     break;
  546.                     
  547.                 case "up-to-the-minute":
  548.                     $tmpl $this->twig->load("modules/up-to-the-minute.html.twig");
  549.                     $html $tmpl->render(array(
  550.                         "module" => $attrs,
  551.                     ));
  552.                     break;
  553.                 case "gallery":
  554.                     $html $this->getGallery($attrs);
  555.                     break;
  556.                 case "content":
  557.                     $type = isset($attrs["ctype"]) ? $attrs["ctype"] : "";
  558.                     $attrs["type"] = $type;
  559.                     $html $this->getContent($attrs);
  560.                     break;
  561.                     
  562.                 case "aar-base-sidebar":
  563.                     $tmpl $this->twig->load("modules/aar-base-sidebar.html.twig");
  564.                     $html $tmpl->render(array(
  565.                         "module" => $attrs,
  566.                     ));
  567.                     break;
  568.                     
  569.                 case "aar-social":
  570.                     $tmpl $this->twig->load("modules/aar-social.html.twig");
  571.                     $html $tmpl->render(array(
  572.                         "module" => $attrs,
  573.                     ));
  574.                     break;
  575.                     
  576.                 case "ad":
  577.                     $html $this->getAds($attrs);
  578.                     break;
  579.             }
  580.         } catch (\Exception $e) {
  581.             if (get_class($e) === "App\Exception\ResourceNotFoundException") {
  582.                 return "";
  583.             }
  584.             // re-throw otherwise
  585.             throw $e;
  586.         }
  587.         return $html;
  588.     }
  589.     // public function show_menu ($twig, $position = "")
  590.     public function show_menu ($position "")
  591.     {
  592.         $menus null;
  593.         try {
  594.             $menus $this->menuHelper->getMenusByPosition($position);
  595.         } catch (\Exception $e) {
  596.             if (get_class($e) === "App\Exception\ResourceNotFoundException") {
  597.                 return "";
  598.             }
  599.             // re-throw otherwise
  600.             throw $e;
  601.         }
  602.         $tmpl $this->twig->load("elements/menu.html.twig");
  603.         return $tmpl->render(array("menus" => $menus));
  604.         /*
  605.         try {
  606.             return $this->menuHelper->buildHtmlByPosition($position);
  607.         } catch (ResourceNotFoundException $e) {
  608.             // fail silently - but ... not working ...
  609.             return "";
  610.         } catch (\Exception $e) {
  611.             // - strange that the custom exception catching is not working above...
  612.             if (get_class($e) === "App\Exception\ResourceNotFoundException") {
  613.                 return "";
  614.             }
  615.             // re-throw otherwise
  616.             throw $e;
  617.         }
  618.         */
  619.     }
  620.     public function get_attributes ($attrs "")
  621.     {
  622.         return $this->defaultHelper->attributeMapToString($attrs);
  623.     }
  624.     public function rcsInclude ($type ""$id ""$attr "")
  625.     {
  626.         $ref null;
  627.         try {
  628.             switch ($type) {
  629.                 case "content" :
  630.                     return "content";
  631.                 case "menu":
  632.                     return $this->menuHelper->buildHTMLById($id);
  633.             }
  634.         } catch (ResouceNotFoundException $e) {
  635.             // fail silently
  636.             return "";
  637.         }
  638.     }
  639.     public function snippetFilter($description$length 320)
  640.     {
  641.         $description strip_tags($description);
  642.         if(strlen($description) > $length) {
  643.             return substr($description0$length) . "...";
  644.         }
  645.         else {
  646.             return $description;
  647.         }
  648.     }
  649.     public function externalLinkFilter($url)
  650.     {
  651.         // The directory 'email' field can be an email address or a url, so adding to use there
  652.         if (filter_var($urlFILTER_VALIDATE_EMAIL)) {
  653.             return "mailto:" $url;
  654.         }
  655.         if(!preg_match("~https?://~i"$url)) {
  656.             return "http://" $url;
  657.         }
  658.         return $url;
  659.     }
  660.     public function timezoneFilter($tz)
  661.     {
  662.         switch($tz){
  663.             case "America/New_York":
  664.                 return "EST";
  665.             case "America/Los_Angeles":
  666.                 return "PST";
  667.             case "America/Chicago":
  668.                 return "CST";
  669.             case "America/Denver":
  670.             case "America/Phoenix":
  671.                 return "MST";
  672.             default:
  673.                 return "";
  674.         }
  675.         /*
  676.         $description = strip_tags($description);
  677.         if(strlen($description) > $length) {
  678.             return substr($description, 0, $length) . "...";
  679.         }
  680.         else {
  681.             return $description;
  682.         }*/
  683.     }
  684.     
  685.     public function rcsDateFormat($date)
  686.     {
  687.         return str_replace(["AM""PM"], ["a.m.""p.m."], date("F j, Y \\a\\t g:i A"strtotime($date)));
  688.     }
  689.     public function rawTwig($content$data = array())
  690.     {
  691.         $tmpl $this->twig->createTemplate($content);
  692.         $html $tmpl->render($data);
  693.         return $html;
  694.     }
  695.     public function twigRandom($stuff)
  696.     {
  697.         $stuff $stuff->toArray();
  698.         shuffle($stuff);
  699.         return new ArrayCollection($stuff);
  700.     }
  701.     public function post_age_format($date)
  702.     {
  703.         $return "";
  704.         if($date->0) {
  705.             $return .= $date->" year" . ($date->== "" "s");
  706.             if($date->0) {
  707.                 $return .= ", "$date->" month" . ($date->== "" "s");
  708.             }
  709.         }
  710.         else if($date->0) {
  711.             $return .= $date->" month" . ($date->== "" "s");
  712.             if($date->>= 7) {
  713.                 $return .= ", "floor($date->7) . " week" . (floor($date->7) == "" "s");
  714.             }
  715.         }
  716.         else if($date->>= 7) {
  717.             $return .= floor($date->7) . " week" . (floor($date->7) == "" "s");
  718.             if(($date->7) > 0) {
  719.                 $return .= ", ". ($date->7) . " day" . (($date->7) == "" "s");
  720.             }
  721.         }
  722.         else if($date->0) {
  723.             $return .= $date->" day" . ($date->== "" "s");
  724.             if($date->0) {
  725.                 $return .= ", "$date->" hour" . ($date->== "" "s");
  726.             }
  727.         }
  728.         else if($date->0) {
  729.             $return .= $date->" hour" . ($date->== "" "s");
  730.             if($date->0) {
  731.                 $return .= ", "$date->" minute" . ($date->== "" "s");
  732.             }
  733.         }
  734.         else if($date->0) {
  735.             $return .= $date->" minute" . ($date->== "" "s");
  736.         }
  737.         else {
  738.             return "Just now";
  739.         }
  740.         return $return " ago";
  741.         //return var_dump($date);
  742.         //$date2 = strtotime($date);
  743.         //return date_format($date2,"Y/m/d");
  744.     }
  745.     public function getFilters()
  746.     {
  747.         // add custom filters below
  748.         return array(
  749.             // new TwigFilter('price', array($this, 'priceFilter')),
  750.             new TwigFilter (
  751.                 "dump",
  752.                 array($this"flatDump")
  753.             ),
  754.             new TwigFilter (
  755.                 "wordpress",
  756.                 array ($this"wordpress")
  757.             ),
  758.             new TwigFilter (
  759.                 "builder",
  760.                 array ($this"builder")
  761.             ),
  762.             new TwigFilter (
  763.                 "snippet",
  764.                 array ($this"snippetFilter")
  765.             ),
  766.             new TwigFilter (
  767.                 "external_link",
  768.                 array ($this"externalLinkFilter")
  769.             ),
  770.             new TwigFilter (
  771.                 "usd",
  772.                 array ($this"usd")
  773.             ),
  774.             new TwigFilter (
  775.                 "timezone",
  776.                 array ($this"timezoneFilter")
  777.             ),
  778.             
  779.             new TwigFilter (
  780.                 "rcsDateFormat",
  781.                 array ($this"rcsDateFormat")
  782.             ),
  783.             
  784.             /*new TwigFilter (
  785.                 "rawTwig",
  786.                 array ($this, "rawTwig")
  787.             ),*/
  788.             // sort random twig fitler
  789.             new TwigFilter (
  790.                 "shuffle",
  791.                 array ($this"twigRandom")
  792.             ),
  793.         );
  794.     }
  795.     public function builder ($content "")
  796.     {
  797.         try {
  798.             $content json_decode($contenttrue);
  799.             $return = array ();
  800.             foreach ($content as $row) {
  801.                 $return[] = "<div class='row'>";
  802.                 foreach ($row as $col) {
  803.                     $return[] = "<div class='col-md-{$col["c"]}'>";
  804.                     $return[] = $col["t"];
  805.                     $return[] = "</div>";
  806.                 }
  807.                 $return[] = "</div>";
  808.             }
  809.         }
  810.         catch (\Exception $e) {
  811.             throw $e;
  812.         }
  813.         // run through the wordpress filter...
  814.         return $this->wordpress(implode(""$return));
  815.     }
  816.     public function flatDump ($data "")
  817.     {
  818.         $data = \Doctrine\Common\Util\Debug::dump($data);
  819.         return $data;
  820.     }
  821.     /**
  822.      * https://developer.wordpress.org/reference/functions/get_html_split_regex/
  823.      */
  824.     protected function get_html_split_regex() {
  825.         static $regex;
  826.         if ( ! isset( $regex ) ) {
  827.             $comments =
  828.                   '!'           // Start of comment, after the <.
  829.                 '(?:'         // Unroll the loop: Consume everything until --> is found.
  830.                 .     '-(?!->)' // Dash not followed by end of comment.
  831.                 .     '[^\-]*+' // Consume non-dashes.
  832.                 ')*+'         // Loop possessively.
  833.                 '(?:-->)?';   // End of comment. If not found, match all input.
  834.             $cdata =
  835.                   '!\[CDATA\['  // Start of comment, after the <.
  836.                 '[^\]]*+'     // Consume non-].
  837.                 '(?:'         // Unroll the loop: Consume everything until ]]> is found.
  838.                 .     '](?!]>)' // One ] not followed by end of comment.
  839.                 .     '[^\]]*+' // Consume non-].
  840.                 ')*+'         // Loop possessively.
  841.                 '(?:]]>)?';   // End of comment. If not found, match all input.
  842.             $escaped =
  843.                   '(?='           // Is the element escaped?
  844.                 .    '!--'
  845.                 '|'
  846.                 .    '!\[CDATA\['
  847.                 ')'
  848.                 '(?(?=!-)'      // If yes, which type?
  849.                 .     $comments
  850.                 '|'
  851.                 .     $cdata
  852.                 ')';
  853.             $regex =
  854.                   '/('              // Capture the entire match.
  855.                 .     '<'           // Find start of element.
  856.                 .     '(?'          // Conditional expression follows.
  857.                 .         $escaped  // Find end of escaped element.
  858.                 .     '|'           // ... else ...
  859.                 .         '[^>]*>?' // Find end of normal element.
  860.                 .     ')'
  861.                 ')/';
  862.         }
  863.         return $regex;
  864.     }
  865.     /**
  866.      * https://developer.wordpress.org/reference/functions/wp_html_split/
  867.      */
  868.     protected function wp_html_split$input ) {
  869.         return preg_split$this->get_html_split_regex(), $input, -1PREG_SPLIT_DELIM_CAPTURE );
  870.     }
  871.     /**
  872.      * https://developer.wordpress.org/reference/functions/wp_replace_in_html_tags/
  873.      */
  874.     protected function wp_replace_in_html_tags$haystack$replace_pairs ) {
  875.         // Find all elements.
  876.         $textarr $this->wp_html_split$haystack );
  877.         $changed false;
  878.         // Optimize when searching for one item.
  879.         if ( === count$replace_pairs ) ) {
  880.             // Extract $needle and $replace.
  881.             foreach ( $replace_pairs as $needle => $replace );
  882.             // Loop through delimiters (elements) only.
  883.             for ( $i 1$c count$textarr ); $i $c$i += ) {
  884.                 if ( false !== strpos$textarr[$i], $needle ) ) {
  885.                     $textarr[$i] = str_replace$needle$replace$textarr[$i] );
  886.                     $changed true;
  887.                 }
  888.             }
  889.         } else {
  890.             // Extract all $needles.
  891.             $needles array_keys$replace_pairs );
  892.             // Loop through delimiters (elements) only.
  893.             for ( $i 1$c count$textarr ); $i $c$i += ) {
  894.                 foreach ( $needles as $needle ) {
  895.                     if ( false !== strpos$textarr[$i], $needle ) ) {
  896.                         $textarr[$i] = strtr$textarr[$i], $replace_pairs );
  897.                         $changed true;
  898.                         // After one strtr() break out of the foreach loop and look at next element.
  899.                         break;
  900.                     }
  901.                 }
  902.             }
  903.         }
  904.         if ( $changed ) {
  905.             $haystack implode$textarr );
  906.         }
  907.         return $haystack;
  908.     }
  909.     /**
  910.      * https://developer.wordpress.org/reference/functions/wpautop/
  911.      */
  912.     public function wordpress ($pee ""$extra_attrs = array ())
  913.     {
  914.         try {
  915.             $br false// ?
  916.             $pre_tags = array();
  917.             if ( trim($pee) === '' )
  918.                 return '';
  919.             // Just to make things a little easier, pad the end.
  920.             $pee $pee "\n";
  921.             /*
  922.              * Pre tags shouldn't be touched by autop.
  923.              * Replace pre tags with placeholders and bring them back after autop.
  924.              */
  925.             if ( strpos($pee'<pre') !== false ) {
  926.                 $pee_parts explode'</pre>'$pee );
  927.                 $last_pee array_pop($pee_parts);
  928.                 $pee '';
  929.                 $i 0;
  930.                 foreach ( $pee_parts as $pee_part ) {
  931.                     $start strpos($pee_part'<pre');
  932.                     // Malformed html?
  933.                     if ( $start === false ) {
  934.                         $pee .= $pee_part;
  935.                         continue;
  936.                     }
  937.                     $name "<pre wp-pre-tag-$i></pre>";
  938.                     $pre_tags[$name] = substr$pee_part$start ) . '</pre>';
  939.                     $pee .= substr$pee_part0$start ) . $name;
  940.                     $i++;
  941.                 }
  942.                 $pee .= $last_pee;
  943.             }
  944.             // Change multiple <br>s into two line breaks, which will turn into paragraphs.
  945.             $pee preg_replace('|<br\s*/?>\s*<br\s*/?>|'"\n\n"$pee);
  946.             $allblocks '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
  947.             // Add a double line break above block-level opening tags.
  948.             $pee preg_replace('!(<' $allblocks '[\s/>])!'"\n\n$1"$pee);
  949.             // Add a double line break below block-level closing tags.
  950.             $pee preg_replace('!(</' $allblocks '>)!'"$1\n\n"$pee);
  951.             // Standardize newline characters to "\n".
  952.             $pee str_replace(array("\r\n""\r"), "\n"$pee);
  953.             // Find newlines in all elements and add placeholders.
  954.             $pee $this->wp_replace_in_html_tags$pee, array( "\n" => " <!-- wpnl --> " ) );
  955.             // Collapse line breaks before and after <option> elements so they don't get autop'd.
  956.             if ( strpos$pee'<option' ) !== false ) {
  957.                 $pee preg_replace'|\s*<option|''<option'$pee );
  958.                 $pee preg_replace'|</option>\s*|''</option>'$pee );
  959.             }
  960.             /*
  961.              * Collapse line breaks inside <object> elements, before <param> and <embed> elements
  962.              * so they don't get autop'd.
  963.              */
  964.             if ( strpos$pee'</object>' ) !== false ) {
  965.                 $pee preg_replace'|(<object[^>]*>)\s*|''$1'$pee );
  966.                 $pee preg_replace'|\s*</object>|''</object>'$pee );
  967.                 $pee preg_replace'%\s*(</?(?:param|embed)[^>]*>)\s*%''$1'$pee );
  968.             }
  969.             /*
  970.              * Collapse line breaks inside <audio> and <video> elements,
  971.              * before and after <source> and <track> elements.
  972.              */
  973.             if ( strpos$pee'<source' ) !== false || strpos$pee'<track' ) !== false ) {
  974.                 $pee preg_replace'%([<\[](?:audio|video)[^>\]]*[>\]])\s*%''$1'$pee );
  975.                 $pee preg_replace'%\s*([<\[]/(?:audio|video)[>\]])%''$1'$pee );
  976.                 $pee preg_replace'%\s*(<(?:source|track)[^>]*>)\s*%''$1'$pee );
  977.             }
  978.             // Collapse line breaks before and after <figcaption> elements.
  979.             if ( strpos$pee'<figcaption' ) !== false ) {
  980.                 $pee preg_replace'|\s*(<figcaption[^>]*>)|''$1'$pee );
  981.                 $pee preg_replace'|</figcaption>\s*|''</figcaption>'$pee );
  982.             }
  983.             // Remove more than two contiguous line breaks.
  984.             $pee preg_replace("/\n\n+/""\n\n"$pee);
  985.             // Split up the contents into an array of strings, separated by double line breaks.
  986.             $pees preg_split('/\n\s*\n/'$pee, -1PREG_SPLIT_NO_EMPTY);
  987.             // Reset $pee prior to rebuilding.
  988.             $pee '';
  989.             // Rebuild the content as a string, wrapping every bit with a <p>.
  990.             foreach ( $pees as $tinkle ) {
  991.                 $pee .= '<p>' trim($tinkle"\n") . "</p>\n";
  992.             }
  993.             // Under certain strange conditions it could create a P of entirely whitespace.
  994.             $pee preg_replace('|<p>\s*</p>|'''$pee);
  995.             // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
  996.             $pee preg_replace('!<p>([^<]+)</(div|address|form)>!'"<p>$1</p></$2>"$pee);
  997.             // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
  998.             $pee preg_replace('!<p>\s*(</?' $allblocks '[^>]*>)\s*</p>!'"$1"$pee);
  999.             // In some cases <li> may get wrapped in <p>, fix them.
  1000.             $pee preg_replace("|<p>(<li.+?)</p>|""$1"$pee);
  1001.             // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
  1002.             $pee preg_replace('|<p><blockquote([^>]*)>|i'"<blockquote$1><p>"$pee);
  1003.             $pee str_replace('</blockquote></p>''</p></blockquote>'$pee);
  1004.             // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
  1005.             $pee preg_replace('!<p>\s*(</?' $allblocks '[^>]*>)!'"$1"$pee);
  1006.             // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
  1007.             $pee preg_replace('!(</?' $allblocks '[^>]*>)\s*</p>!'"$1"$pee);
  1008.             // Optionally insert line breaks.
  1009.             if ( $br ) {
  1010.                 // Replace newlines that shouldn't be touched with a placeholder.
  1011.                 $pee preg_replace_callback('/<(script|style).*?<\/\\1>/s''_autop_newline_preservation_helper'$pee);
  1012.                 // Normalize <br>
  1013.                 $pee str_replace( array( '<br>''<br/>' ), '<br />'$pee );
  1014.                 // Replace any new line characters that aren't preceded by a <br /> with a <br />.
  1015.                 $pee preg_replace('|(?<!<br />)\s*\n|'"<br />\n"$pee);
  1016.                 // Replace newline placeholders with newlines.
  1017.                 $pee str_replace('<WPPreserveNewline />'"\n"$pee);
  1018.             }
  1019.             // If a <br /> tag is after an opening or closing block tag, remove it.
  1020.             $pee preg_replace('!(</?' $allblocks '[^>]*>)\s*<br />!'"$1"$pee);
  1021.             // If a <br /> tag is before a subset of opening or closing block tags, remove it.
  1022.             $pee preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!''$1'$pee);
  1023.             $pee preg_replace"|\n</p>$|"'</p>'$pee );
  1024.             // Replace placeholder <pre> tags with their original content.
  1025.             if ( !empty($pre_tags) )
  1026.                 $pee str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
  1027.             // Restore newlines in all elements.
  1028.             if ( false !== strpos$pee'<!-- wpnl -->' ) ) {
  1029.                 $pee str_replace( array( ' <!-- wpnl --> ''<!-- wpnl -->' ), "\n"$pee );
  1030.             }
  1031.             // WordPress shortcodes come in 2 flavors ...
  1032.             // EWG 12/20: New tag shortcodes
  1033.             //TEMPORARY: running twice until I can get it to run recursively w/o crashing
  1034.             $pee $this->tagShortcodes($pee);
  1035.             $pee $this->tagShortcodes($pee);
  1036.             /*
  1037.             preg_match_all('/\[url\](.*?)\[\/url\]/s', $pee, $matches);
  1038.             if (!empty($matches)) {
  1039.                 foreach ($matches as $val) {
  1040.                     $pee = str_replace($val[0], "<a href='$val[2]' target='_blank'>".$val[2]."</a>", $pee);
  1041.                 }
  1042.             }
  1043.             */
  1044.             // tag shortcodes
  1045.             preg_match_all("#\[([^\[]*)\[\/#"$pee$matches);
  1046.             if (!empty($matches[1])) {
  1047.                 foreach ($matches[1] as $i => $shortcode) {
  1048.                     $temp explode(" "$shortcode);
  1049.                     $type array_shift($temp);
  1050.                     $attr implode(" "$temp);
  1051.                     // $attr = htmlspecialchars_decode($attr);
  1052.                     $attr str_replace("&nbsp;"" "$attr);
  1053.                     $attr html_entity_decode($attr);
  1054.                     $pos strpos($attr"]");
  1055.                     $text substr($attr$pos 1);
  1056.                     $attr substr($attr0$pos);
  1057.                     try {
  1058.                         $str "<temp $attr />";
  1059.                         $xml = new SimpleXMLElement($str);
  1060.                         $attr current($xml->attributes());
  1061.                     } catch (\Exception $e) {
  1062.                         // echo "<pre>";
  1063.                         // var_dump($e->getMessage(), $str);
  1064.                         // exit;
  1065.                     }
  1066.                     if (is_array($attr)) {
  1067.                         $attr["html"] = $text;
  1068.                     }
  1069.                     /*
  1070.                     echo "<pre>";
  1071.                     var_dump($attr);
  1072.                     exit;
  1073.                     */
  1074.                     switch ($type) {
  1075.                         case "caption":
  1076.                             $pee str_replace(
  1077.                                 "{$matches[0][$i]}$type]",
  1078.                                 $this->getCaption($attr),
  1079.                                 $pee
  1080.                             );
  1081.                             break;
  1082.                     }
  1083.                 }
  1084.             }
  1085.             // members and non-members shortcodes. Only displays these sections for RCS-Club members or non-members
  1086.             $user $this->security->getUser();
  1087.             $isMember false;
  1088.             if($user && $user->isMember()) {
  1089.                 $isMember true;
  1090.             }
  1091.             preg_match_all("'\[members\](.*?)\[/members\]'si"$pee$matches);
  1092.             if (!empty($matches[1])) {
  1093.                 foreach ($matches[1] as $i => $match) {
  1094.                     if($isMember) {
  1095.                         $replace $matches[1][$i];
  1096.                     }
  1097.                     else {
  1098.                         $replace "";
  1099.                     }
  1100.                     $pee str_replace(
  1101.                         $matches[0][$i],
  1102.                          $replace,
  1103.                         $pee
  1104.                     );
  1105.                 }
  1106.             }
  1107.             preg_match_all("'\[non-members\](.*?)\[/non-members\]'si"$pee$matches);
  1108.             if (!empty($matches[1])) {
  1109.                 foreach ($matches[1] as $i => $match) {
  1110.                     if(!$isMember) {
  1111.                         $replace $matches[1][$i];
  1112.                     }
  1113.                     else {
  1114.                         $replace "";
  1115.                     }
  1116.                     $pee str_replace(
  1117.                         $matches[0][$i],
  1118.                          $replace,
  1119.                         $pee
  1120.                     );
  1121.                 }
  1122.             }
  1123.             // self closing shortcodes (not really working? see the members / non-members above for more specific preg_match that works)
  1124.             preg_match_all("/\[([^\]]*)]/"$pee$matches);
  1125.             if (!empty($matches[1])) {
  1126.                 foreach ($matches[1] as $i => $shortcode) {
  1127.                     $temp explode(" "$shortcode);
  1128.                     $type array_shift($temp);
  1129.                     $attr implode(" "$temp);
  1130.                     $attr str_replace("&nbsp;"" "$attr);
  1131.                     $attr html_entity_decode($attr);
  1132.                     $attr str_replace("&""&amp;"$attr);
  1133.                     //$attr = str_replace(array('&', '<', '>', '\'', '"'), array('&amp;', '&lt;', '&gt;', '&apos;', '&quot;'), $attr);
  1134.                     try {
  1135.                         $str "<temp $attr />";
  1136.                         $xml = new SimpleXMLElement($str);
  1137.                         $attr current($xml->attributes());
  1138.                     } catch (\Exception $e) {
  1139.                         // echo "<pre>";
  1140.                         // var_dump($e->getMessage(), $str);
  1141.                         // exit;
  1142.                     }
  1143.                     
  1144.                     switch ($type) {
  1145.                         // FontAwesome shortcodes
  1146.                         case "fa":
  1147.                             $class = isset($attr["class"]) ? $attr["class"] : "";
  1148.                             $pee str_replace(
  1149.                                 $matches[0][$i],
  1150.                                 "<i class=\"fa fa-{$attr["type"]} {$class}\"></i>",
  1151.                                 $pee
  1152.                             );
  1153.                             break;
  1154.                         //Adding some basic tags here...
  1155.                         //Should be in non self closing shortcodes section above but can't get those to work at the moment
  1156.                         case "b":
  1157.                             $pee str_replace($matches[0][$i], "<b>"$pee);
  1158.                             break;
  1159.                         case "/b":
  1160.                             $pee str_replace($matches[0][$i], "</b>"$pee);
  1161.                             break;
  1162.                         case "i":
  1163.                             $pee str_replace($matches[0][$i], "<i>"$pee);
  1164.                             break;
  1165.                         case "/i":
  1166.                             $pee str_replace($matches[0][$i], "</i>"$pee);
  1167.                             break;
  1168.                         case "u":
  1169.                             $pee str_replace($matches[0][$i], "<u>"$pee);
  1170.                             break;
  1171.                         case "/u":
  1172.                             $pee str_replace($matches[0][$i], "</u>"$pee);
  1173.                             break;
  1174.                         case "quote/":
  1175.                             $pee str_replace($matches[0][$i], "<blockquote>"$pee);
  1176.                             break;
  1177.                         case "/quote":
  1178.                             $pee str_replace($matches[0][$i], "</blockquote>"$pee);
  1179.                             break;
  1180.                         case "embed":
  1181.                             $pee str_replace($matches[0][$i], "<iframe width='560' height='315' src='"$pee);
  1182.                             break;
  1183.                         case "/embed":
  1184.                             $pee str_replace($matches[0][$i], "' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen></iframe>"$pee);
  1185.                             break;
  1186.                             
  1187.                         // Gravity Forms ...
  1188.                         // for time being simply hard code all fields ...
  1189.                         // will create a new module that will allow adding custom fields ... see below
  1190.                         case "gravityform":
  1191.                             $pee str_replace(
  1192.                                 $matches[0][$i],
  1193.                                 $this->getGravityForm($extra_attrs$attr),
  1194.                                 $pee
  1195.                             );
  1196.                             break;
  1197.                         case "contact-form-7":
  1198.                             $pee str_replace(
  1199.                                 $matches[0][$i],
  1200.                                 $this->getContactForm($extra_attrs$attr),
  1201.                                 $pee
  1202.                             );
  1203.                             break;
  1204.                         // To replace the above forms ...
  1205.                         case "symform":
  1206.                             $pee str_replace(
  1207.                                 $matches[0][$i],
  1208.                                 $this->getSymfonyForm($attr),
  1209.                                 $pee
  1210.                             );
  1211.                             break;
  1212.                         case "content":
  1213.                             $pee str_replace(
  1214.                                 $matches[0][$i],
  1215.                                 $this->getContent($attr),
  1216.                                 $pee
  1217.                             );
  1218.                             break;
  1219.                         case "category":
  1220.                             $pee str_replace(
  1221.                                 $matches[0][$i],
  1222.                                 $this->getCategoryList($attr),
  1223.                                 $pee
  1224.                             );
  1225.                             break;
  1226.                         case "customers":
  1227.                             $pee str_replace(
  1228.                                 $matches[0][$i],
  1229.                                 $this->getCustomerList($attr),
  1230.                                 $pee
  1231.                             );
  1232.                             break;
  1233.                         case "gallery":
  1234.                             $pee str_replace(
  1235.                                 $matches[0][$i],
  1236.                                 $this->getGallery($attr),
  1237.                                 $pee
  1238.                             );
  1239.                             break;
  1240.                         case "mediagroup":
  1241.                             $pee str_replace(
  1242.                                 $matches[0][$i],
  1243.                                 $this->getMediaGroup($attr),
  1244.                                 $pee
  1245.                             );
  1246.                             break;
  1247.                         case "twitter":
  1248.                             $pee str_replace(
  1249.                                 $matches[0][$i],
  1250.                                 $this->getTweets($attr),
  1251.                                 $pee
  1252.                             );
  1253.                             break;
  1254.                         case "facebook":
  1255.                             $pee str_replace(
  1256.                                 $matches[0][$i],
  1257.                                 $this->getFBPost($attr),
  1258.                                 $pee
  1259.                             );
  1260.                             break;
  1261.                         case "poll":
  1262.                             $pee str_replace(
  1263.                                 $matches[0][$i],
  1264.                                 $this->getPoll($attr),
  1265.                                 $pee
  1266.                             );
  1267.                             break;
  1268.                         case "ad":
  1269.                             $pee str_replace(
  1270.                                 $matches[0][$i],
  1271.                                 $this->getAds($attr),
  1272.                                 $pee
  1273.                             );
  1274.                             break;
  1275.                     }
  1276.                 }
  1277.             }
  1278.         } catch (Exception $e) {
  1279.         }
  1280.         // for time being replace old events until we completely remove the system...
  1281.         //
  1282.         return $pee;
  1283.     }
  1284.     public function getCaption ($attr = array())
  1285.     {
  1286.         $html "";
  1287.         try {
  1288.             $tmpl $this->twig->load("modules/captions.html.twig");
  1289.             $html $tmpl->render(array(
  1290.                 "module" => $attr,
  1291.             ));
  1292.         } catch (Exception $e) {
  1293.         }
  1294.         return $html;
  1295.     }
  1296.     public function getCategoryList ($attr = array ())
  1297.     {
  1298.         $html "";
  1299.         try {
  1300.             if (isset($attr["taxonomy"])) {
  1301.                 $categories $this->categoryHelper->getCategoriesByTaxonomy ($attr["taxonomy"]);
  1302.                 $attr["data"] = $categories;
  1303.                 $tmpl $this->twig->load("modules/category-list.html.twig");
  1304.                 $html $tmpl->render(array(
  1305.                     "module" => $attr
  1306.                 ));
  1307.             }
  1308.         } catch (Exception $e) {
  1309.         }
  1310.         return $html;
  1311.     }
  1312.     //Currently just used to get customers who have content of a certain type, and display a list that links to their content pages
  1313.     //(Made for the RLW page's sidebar)
  1314.     public function getCustomerList ($attr = array ())
  1315.     {
  1316.         $html "";
  1317.         try {
  1318.             if (isset($attr["ctype"])) {
  1319.                 $customers $this->customerHelper->getCustomersByContentType ($attr["ctype"]);
  1320.                 $attr["data"] = $customers;
  1321.                 $tmpl $this->twig->load("modules/customer-list.html.twig");
  1322.                 $html $tmpl->render(array(
  1323.                     "module" => $attr
  1324.                 ));
  1325.             }
  1326.         } catch (Exception $e) {
  1327.         }
  1328.         return $html;
  1329.     }
  1330.     protected function getGallery ($attr = array ())
  1331.     {
  1332.         $attr array_merge([
  1333.             "columns" => 3,
  1334.             "link" => "file",
  1335.             "ids" => [],
  1336.             "gallerySlug" => "",
  1337.             "links" => [],
  1338.             "idtype" => "",
  1339.             "limit" => ""
  1340.         ], $attr);
  1341.         $attr["class"] = !empty($attr["class"]) ? $attr["class"] . " gallery" "gallery";
  1342.         if (!empty($attr["ids"]) && is_string($attr["ids"])) {
  1343.             $attr["ids"] = explode(","$attr["ids"]);
  1344.         }
  1345.         if (!empty($attr["links"]) && is_string($attr["links"])) {
  1346.             $attr["links"] = array_map('trim'explode(","$attr["links"]));
  1347.         }
  1348.         $limit = (int) $attr["limit"];
  1349.         $data = array ();
  1350.         foreach ($attr["ids"] as $id) {
  1351.             try {
  1352.                 if($attr["idtype"] == "old") {
  1353.                     $media $this->mediaHelper->getMediaByOldId($id);
  1354.                 }
  1355.                 else {
  1356.                     $media $this->mediaHelper->getMediaById($id);
  1357.                 }
  1358.                 $data[] = $media;
  1359.             } catch (\Exception $e) {
  1360.                 // ignore
  1361.             }
  1362.         }
  1363.         $attr["mitems"] = [];
  1364.         if(!empty($attr["gallerySlug"]) && $attr["gallerySlug"]) {
  1365.             $data = [];//media
  1366.             $mitems = [];
  1367.             $gallery $this->contentHelper->getContentBySlug(Content::GALLERY$attr["gallerySlug"]);
  1368.             $mediaIds = [];
  1369.             foreach($gallery->getMediaGroupContainers() as $mgroupc) {
  1370.                 $mgroup $mgroupc->getMediaGroup();
  1371.                 if($mgroup) {
  1372.                     foreach($mgroup->getMediaGroupItems() as $mitem) {
  1373.                         $mitems[] = $mitem;
  1374.                         $media $mitem->getMedia();
  1375.                         if($media) {
  1376.                             $data[] = $media;
  1377.                         }
  1378.                     }
  1379.                 }
  1380.             }
  1381.             $attr["mitems"] = $mitems;
  1382.         }
  1383.         if($limit && $limit count($data)) {
  1384.             $rand $this->getUniqueRandomNumbers(0count($data)-1$limit);
  1385.             $links = array();
  1386.             $attr["data"] = array();
  1387.             foreach($rand as $r) {
  1388.                 $attr["data"][] = $data[$r];
  1389.                 if($attr["links"]) {
  1390.                     $links[] = $attr["links"][$r];
  1391.                 }
  1392.             }
  1393.             $attr["links"] = $links;
  1394.         }
  1395.         else {
  1396.             $attr["data"] = $data;
  1397.         }
  1398.         $tmpl $this->twig->load("modules/gallery-display.html.twig");
  1399.         $html $tmpl->render(array(
  1400.             "module" => $attr,
  1401.         ));
  1402.         return $html;
  1403.     }
  1404.     protected function getContactForm ($meta = array (), $attr = array ())
  1405.     {
  1406.         $module "";
  1407.         // hack to convert current gravity forms to default lead form
  1408.         $buttonColor "#F1592A";
  1409.         $buttonText "Submit";
  1410.         
  1411.         if($attr["id"] == 10537) { //contact us
  1412.             $module implode(" ", array (
  1413.                 '<form method="post" class="py-4">',
  1414.                 '<label class="btn-block"><span>First Name:</span>
  1415.                     <input
  1416.                         type="text"
  1417.                         class="form-control"
  1418.                         placeholder="Your First Name"
  1419.                         name="contact[firstname]"
  1420.                         required
  1421.                     />
  1422.                 </label>',
  1423.                 '<label class="btn-block"><span>Last Name:</span>
  1424.                     <input
  1425.                         type="text"
  1426.                         class="form-control"
  1427.                         placeholder="Your Last Name"
  1428.                         name="contact[lastname]"
  1429.                         required
  1430.                     />
  1431.                 </label>',
  1432.                 '<label class="btn-block"><span>Email:</span>
  1433.                     <input
  1434.                         type="text"
  1435.                         class="form-control"
  1436.                         placeholder="Your Email Address"
  1437.                         name="contact[email]"
  1438.                         required
  1439.                     />
  1440.                 </label>',
  1441.                 
  1442.                 '<label class="btn-block"><span>State / Region:</span>
  1443.                     <input
  1444.                         type="text"
  1445.                         class="form-control"
  1446.                         placeholder="Your State / Region"
  1447.                         name="contact[state]"
  1448.                         required
  1449.                     />
  1450.                 </label>',
  1451.                 
  1452.                 '<label class="btn-block"><span>ZIP / Postal Code:</span>
  1453.                     <input
  1454.                         type="text"
  1455.                         class="form-control"
  1456.                         placeholder="Your ZIP Code"
  1457.                         name="contact[zip]"
  1458.                         required
  1459.                     />
  1460.                 </label>',
  1461.                 
  1462.                 '<label class="btn-block"><span>Subject:</span>
  1463.                     <input
  1464.                         type="text"
  1465.                         class="form-control"
  1466.                         placeholder="The Subject of Your Message"
  1467.                         name="contact[subject]"
  1468.                         required
  1469.                     />
  1470.                 </label>',
  1471.                 '<label class="btn-block"><span>Your Message:</span>
  1472.                     <textarea
  1473.                         type="text"
  1474.                         class="form-control"
  1475.                         placeholder="Your Message"
  1476.                         name="contact[message]"
  1477.                         required
  1478.                     ></textarea>
  1479.                 </label>',
  1480.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  1481.                 '<div style="text-align: center;">
  1482.                 <button
  1483.                     class="btn mt-3"
  1484.                     type="submit"
  1485.                     style="color: #fff; background: ' $buttonColor ';"
  1486.                 >' $buttonText '</button>
  1487.                 </div>
  1488.                 </form>',
  1489.             ));
  1490.         }
  1491.         elseif($attr["id"] == 8457) { //have a question
  1492.             $module implode(" ", array (
  1493.                 '<form method="post" class="py-4" enctype="multipart/form-data">',
  1494.                 '<label class="btn-block"><span>First Name:</span>
  1495.                     <input
  1496.                         type="text"
  1497.                         class="form-control"
  1498.                         placeholder="Your First Name"
  1499.                         name="contact[firstname]"
  1500.                         required
  1501.                     />
  1502.                 </label>',
  1503.                 '<label class="btn-block"><span>Last Name:</span>
  1504.                     <input
  1505.                         type="text"
  1506.                         class="form-control"
  1507.                         placeholder="Your Last Name"
  1508.                         name="contact[lastname]"
  1509.                         required
  1510.                     />
  1511.                 </label>',
  1512.                 '<label class="btn-block"><span>Email:</span>
  1513.                     <input
  1514.                         type="text"
  1515.                         class="form-control"
  1516.                         placeholder="Your Email Address"
  1517.                         name="contact[email]"
  1518.                         required
  1519.                     />
  1520.                 </label>',
  1521.                 
  1522.                 '<label class="btn-block"><span>Phone (to help with complicated answers):</span>
  1523.                     <input
  1524.                         type="text"
  1525.                         class="form-control"
  1526.                         placeholder="Your Phone"
  1527.                         name="contact[phone]"
  1528.                         required
  1529.                     />
  1530.                 </label>',
  1531.                 
  1532.                 '<label class="btn-block"><span>Zip Code (to determine area of country and requirements):</span>
  1533.                     <input
  1534.                         type="text"
  1535.                         class="form-control"
  1536.                         placeholder="Your Zip Code"
  1537.                         name="contact[zip]"
  1538.                         required
  1539.                     />
  1540.                 </label>',
  1541.                 
  1542.                 '<label class="btn-block"><span>State / Region:</span>
  1543.                     <input
  1544.                         type="text"
  1545.                         class="form-control"
  1546.                         placeholder="Your State / Region"
  1547.                         name="contact[state]"
  1548.                         required
  1549.                     />
  1550.                 </label>',
  1551.                 
  1552.                 '<label class="btn-block"><span>What\'s your Question?:</span>
  1553.                     <textarea
  1554.                         type="text"
  1555.                         class="form-control"
  1556.                         placeholder="Your Question"
  1557.                         name="contact[question]"
  1558.                         required
  1559.                     ></textarea>
  1560.                 </label>',
  1561.                 
  1562.                 '<label class="btn-block"><span>Photo of the problem area:</span>
  1563.                     <input type="file" class="form-control-file" id="photo" name="photo">
  1564.                 </label>',
  1565.                 
  1566.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  1567.                 '<div style="text-align: center;">
  1568.                 <button
  1569.                     class="btn mt-3"
  1570.                     type="submit"
  1571.                     style="color: #fff; background: ' $buttonColor ';"
  1572.                 >' $buttonText '</button>
  1573.                 </div>
  1574.                 </form>',
  1575.             ));
  1576.         }
  1577.         
  1578.         return $module;
  1579.         
  1580.     }
  1581.     
  1582.     protected function getGravityForm ($meta = array (), $attr = array ())
  1583.     {
  1584.         // hack to convert current gravity forms to default lead form
  1585.         $buttonColor "#A41822";
  1586.         if (!empty($meta["btn_color"])) {
  1587.             $buttonColor $meta["btn_color"];
  1588.         }
  1589.         $buttonText "Submit";
  1590.         if (!empty($meta["btn_text"])) {
  1591.             $buttonText $meta["btn_text"];
  1592.         }
  1593.         /* - Too complex for now - we will replace with a form building entity soon ...
  1594.         $factory = Forms::createFormFactory();
  1595.         $form = $factory
  1596.             ->create(
  1597.                 DirectoryLeadType::class,
  1598.                 new Lead()
  1599.             )->createView();
  1600.         $module = $this->show_module(array(
  1601.             "type" => "form2",
  1602.             "form" => $form,
  1603.         ));
  1604.         */
  1605.         // for time being just create static default form
  1606.         if($attr["id"] == 2) { //contact us
  1607.             $module implode(" ", array (
  1608.                 '<form method="post" class="py-4">',
  1609.                 '<label class="btn-block"><span>First Name:</span>
  1610.                     <input
  1611.                         type="text"
  1612.                         class="form-control"
  1613.                         placeholder="Your First Name"
  1614.                         name="contact[firstname]"
  1615.                         required
  1616.                     />
  1617.                 </label>',
  1618.                 '<label class="btn-block"><span>Last Name:</span>
  1619.                     <input
  1620.                         type="text"
  1621.                         class="form-control"
  1622.                         placeholder="Your Last Name"
  1623.                         name="contact[lastname]"
  1624.                         required
  1625.                     />
  1626.                 </label>',
  1627.                 '<label class="btn-block"><span>Email:</span>
  1628.                     <input
  1629.                         type="text"
  1630.                         class="form-control"
  1631.                         placeholder="Your Email Address"
  1632.                         name="contact[email]"
  1633.                         required
  1634.                     />
  1635.                 </label>',
  1636.                 
  1637.                 '<label class="btn-block"><span>State / Region:</span>
  1638.                     <input
  1639.                         type="text"
  1640.                         class="form-control"
  1641.                         placeholder="Your State / Region"
  1642.                         name="contact[state]"
  1643.                         required
  1644.                     />
  1645.                 </label>',
  1646.                 
  1647.                 '<label class="btn-block"><span>ZIP / Postal Code:</span>
  1648.                     <input
  1649.                         type="text"
  1650.                         class="form-control"
  1651.                         placeholder="Your ZIP Code"
  1652.                         name="contact[zip]"
  1653.                         required
  1654.                     />
  1655.                 </label>',
  1656.                 '<label class="btn-block"><span>Subject:</span>
  1657.                     <input
  1658.                         type="text"
  1659.                         class="form-control"
  1660.                         placeholder="The Subject of Your Message"
  1661.                         name="contact[subject]"
  1662.                         required
  1663.                     />
  1664.                 </label>',
  1665.                 '<label class="btn-block"><span>Your Message:</span>
  1666.                     <textarea
  1667.                         type="text"
  1668.                         class="form-control"
  1669.                         placeholder="Your Message"
  1670.                         name="contact[message]"
  1671.                         required
  1672.                     ></textarea>
  1673.                 </label>',
  1674.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  1675.                 '<div style="text-align: center;">
  1676.                 <button
  1677.                     class="btn mt-3"
  1678.                     type="submit"
  1679.                     style="color: #fff; background: ' $buttonColor ';"
  1680.                 >' $buttonText '</button>
  1681.                 </div>
  1682.                 </form>',
  1683.             ));
  1684.         }
  1685.         elseif($attr["id"] == 3) { //week in review sign up
  1686.             $module implode(" ", array (
  1687.                 '<form method="post" class="py-4">',
  1688.                 '<div class="row">',
  1689.                 '<div class="col-sm-6">',
  1690.                 '<label class="btn-block"><span>First Name:</span>
  1691.                     <input
  1692.                         type="text"
  1693.                         class="form-control"
  1694.                         placeholder="Your First Name"
  1695.                         name="lead[firstname]"
  1696.                         required
  1697.                     />
  1698.                 </label>',
  1699.                 '</div>',
  1700.                 '<div class="col-sm-6">',
  1701.                 '<label class="btn-block"><span>Last Name:</span>
  1702.                     <input
  1703.                         type="text"
  1704.                         class="form-control"
  1705.                         placeholder="Your Last Name"
  1706.                         name="lead[lastname]"
  1707.                         required
  1708.                     />
  1709.                 </label>',
  1710.                 '</div>',
  1711.                 '</div>',
  1712.                 '<label class="btn-block"><span>Email:</span>
  1713.                     <input
  1714.                         type="text"
  1715.                         class="form-control"
  1716.                         placeholder="Your Email Address"
  1717.                         name="lead[email]"
  1718.                         required
  1719.                     />
  1720.                 </label>',
  1721.                 '<label class="btn-block"><span>Company:</span>
  1722.                     <input
  1723.                         type="text"
  1724.                         class="form-control"
  1725.                         placeholder="Your Company"
  1726.                         name="lead[company]"
  1727.                         required
  1728.                     />
  1729.                 </label>',
  1730.                 '<label class="btn-block"><span>Type of Work Performed:</span>
  1731.                     <select
  1732.                         class="form-control"
  1733.                         name="lead[contractor_type]"
  1734.                         required
  1735.                     >
  1736.                     <option value="Primarily Commercial">Primarily Commercial</option>
  1737.                     <option value="Primarily Residential">Primarily Residential</option>
  1738.                     <option value="Both">Both</option>
  1739.                     <option value="Not a Contractor">Not a Contractor</option>
  1740.                     </select>
  1741.                 </label>',
  1742.                 '<label class="btn-block"><span>Country:</span></label>
  1743.                 <label class="btn-block">
  1744.                     <input
  1745.                         type="radio"
  1746.                         name="lead[country]"
  1747.                         value="United States"
  1748.                         checked
  1749.                         required
  1750.                     />
  1751.                     <span>United States</span>
  1752.                 </label>
  1753.                 <label class="btn-block">
  1754.                     <input
  1755.                         type="radio"
  1756.                         name="lead[country]"
  1757.                         value="Canada"
  1758.                         required
  1759.                     />
  1760.                     <span>Canada</span>
  1761.                 </label>
  1762.                 <label class="btn-block">
  1763.                     <input
  1764.                         type="radio"
  1765.                         name="lead[country]"
  1766.                         value="European Countries"
  1767.                         required
  1768.                     />
  1769.                     <span>European Countries</span>
  1770.                 </label>
  1771.                 <label class="btn-block">
  1772.                     <input
  1773.                         type="radio"
  1774.                         name="lead[country]"
  1775.                         value="Other"
  1776.                         required
  1777.                     />
  1778.                     <span><input
  1779.                         type="text"
  1780.                         placeholder="Other"
  1781.                         name="lead[country_other]"
  1782.                     /></span>
  1783.                 </label>',
  1784.                 '<label class="btn-block"><span>Business Type:</span>
  1785.                     <select
  1786.                         class="form-control"
  1787.                         name="lead[business_type]"
  1788.                         required
  1789.                     >
  1790.                     <option value="Roofing Contractor">Roofing Contractor</option>
  1791.                     <option value="Exterior/General Contractor">Exterior/General Contractor</option>
  1792.                     <option value="Distributor">Distributor</option>
  1793.                     <option value="Manufacturer/Business Services">Manufacturer/Business Services</option>
  1794.                     <option value="Other">Other</option>
  1795.                     </select>
  1796.                 </label>',
  1797.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  1798.                 '<div style="text-align: center;">
  1799.                 <button
  1800.                     class="btn mt-3"
  1801.                     type="submit"
  1802.                     style="color: #fff; background: ' $buttonColor ';"
  1803.                 >' $buttonText '</button>
  1804.                 </div>
  1805.                 </form>',
  1806.             ));
  1807.         }
  1808.         elseif($attr["id"] == 4) { //membership
  1809.             $module implode(" ", array (
  1810.                 '<form method="post" class="py-4">',
  1811.                 '<label class="btn-block"><span>First Name:</span>
  1812.                     <input
  1813.                         type="text"
  1814.                         class="form-control"
  1815.                         placeholder="Your First Name"
  1816.                         name="contact[firstname]"
  1817.                         required
  1818.                     />
  1819.                 </label>',
  1820.                 '<label class="btn-block"><span>Last Name:</span>
  1821.                     <input
  1822.                         type="text"
  1823.                         class="form-control"
  1824.                         placeholder="Your Last Name"
  1825.                         name="contact[lastname]"
  1826.                         required
  1827.                     />
  1828.                 </label>',
  1829.                 '<label class="btn-block"><span>Phone:</span>
  1830.                     <input
  1831.                         type="text"
  1832.                         class="form-control"
  1833.                         placeholder="Your Phone"
  1834.                         name="lead[phone]"
  1835.                     />
  1836.                 </label>',
  1837.                 '<label class="btn-block"><span>Email:</span>
  1838.                     <input
  1839.                         type="text"
  1840.                         class="form-control"
  1841.                         placeholder="Your Email Address"
  1842.                         name="contact[email]"
  1843.                         required
  1844.                     />
  1845.                 </label>',
  1846.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  1847.                 '<div style="text-align: center;">
  1848.                 <button
  1849.                     class="btn mt-3"
  1850.                     type="submit"
  1851.                     style="color: #fff; background: ' $buttonColor ';"
  1852.                 >' $buttonText '</button>
  1853.                 </div>
  1854.                 </form>',
  1855.             ));
  1856.         }
  1857.         elseif($attr["id"] == 14 || $attr["id"] == 96) { //order roofing respect sticker
  1858.             $user $this->security->getUser();
  1859.             if($user) {
  1860.                 $module implode(" ", array (
  1861.                     '<form method="post" class="py-4">',
  1862.                     '<div class="row">',
  1863.                     '<div class="col-sm-6">',
  1864.                     '<label class="btn-block"><span>First Name:</span>
  1865.                         <input
  1866.                             type="text"
  1867.                             class="form-control"
  1868.                             placeholder="Your First Name"
  1869.                             name="lead[firstname]"
  1870.                             required
  1871.                         />
  1872.                     </label>',
  1873.                     '</div>',
  1874.                     '<div class="col-sm-6">',
  1875.                     '<label class="btn-block"><span>Last Name:</span>
  1876.                         <input
  1877.                             type="text"
  1878.                             class="form-control"
  1879.                             placeholder="Your Last Name"
  1880.                             name="lead[lastname]"
  1881.                             required
  1882.                         />
  1883.                     </label>',
  1884.                     '</div>',
  1885.                     '</div>',
  1886.                     '<label class="btn-block"><span>Company:</span>
  1887.                         <input
  1888.                             type="text"
  1889.                             class="form-control"
  1890.                             placeholder="Your Company"
  1891.                             name="lead[company]"
  1892.                             required
  1893.                         />
  1894.                     </label>',
  1895.                     '<label class="btn-block"><span>Phone:</span>
  1896.                         <input
  1897.                             type="text"
  1898.                             class="form-control"
  1899.                             placeholder="Your Phone"
  1900.                             name="lead[phone]"
  1901.                             required
  1902.                         />
  1903.                     </label>',
  1904.                     '<label class="btn-block"><span>Email:</span>
  1905.                         <input
  1906.                             type="text"
  1907.                             class="form-control"
  1908.                             placeholder="Your Email Address"
  1909.                             name="lead[email]"
  1910.                             required
  1911.                         />
  1912.                     </label>',
  1913.                     '<div class="row">',
  1914.                     '<div class="col-sm-6">',
  1915.                     '<label class="btn-block"><span>Street Address:</span>
  1916.                         <input
  1917.                             type="text"
  1918.                             class="form-control"
  1919.                             placeholder="Your Address"
  1920.                             name="lead[address1]"
  1921.                             required
  1922.                         />
  1923.                     </label>',
  1924.                     '</div>',
  1925.                     '<div class="col-sm-6">',
  1926.                     '<label class="btn-block"><span>Address Line 2:</span>
  1927.                         <input
  1928.                             type="text"
  1929.                             class="form-control"
  1930.                             placeholder="Your Address Line 2"
  1931.                             name="lead[address2]"
  1932.                         />
  1933.                     </label>',
  1934.                     '</div>',
  1935.                     '</div>',
  1936.                     '<div class="row">',
  1937.                     '<div class="col-sm-6">',
  1938.                     '<label class="btn-block"><span>City:</span>
  1939.                         <input
  1940.                             type="text"
  1941.                             class="form-control"
  1942.                             placeholder="Your City"
  1943.                             name="lead[city]"
  1944.                             required
  1945.                         />
  1946.                     </label>',
  1947.                     '</div>',
  1948.                     '<div class="col-sm-6">',
  1949.                     '<label class="btn-block"><span>State / Providence / Region:</span>
  1950.                         <input
  1951.                             type="text"
  1952.                             class="form-control"
  1953.                             placeholder="Your Region"
  1954.                             name="lead[state]"
  1955.                             required
  1956.                         />
  1957.                     </label>',
  1958.                     '</div>',
  1959.                     '</div>',
  1960.                     '<label class="btn-block"><span>ZIP / Postal Code:</span>
  1961.                         <input
  1962.                             type="text"
  1963.                             class="form-control"
  1964.                             placeholder="Your Postal Code"
  1965.                             name="lead[zip]"
  1966.                             required
  1967.                         />
  1968.                     </label>',
  1969.                     '<label class="btn-block"><span>Type of Contractor:</span></label>
  1970.                     <label class="btn-block">
  1971.                         <input
  1972.                             type="radio"
  1973.                             name="lead[contractor_type]"
  1974.                             value="Primarily Residential"
  1975.                             required
  1976.                         />
  1977.                         <span>Primarily Residential</span>
  1978.                     </label>
  1979.                     <label class="btn-block">
  1980.                         <input
  1981.                             type="radio"
  1982.                             name="lead[contractor_type]"
  1983.                             value="Primarily Commercial"
  1984.                             required
  1985.                         />
  1986.                         <span>Primarily Commercial</span>
  1987.                     </label>
  1988.                     <label class="btn-block">
  1989.                         <input
  1990.                             type="radio"
  1991.                             name="lead[contractor_type]"
  1992.                             value="Both"
  1993.                             required
  1994.                         />
  1995.                         <span>Both</span>
  1996.                     </label>
  1997.                     <label class="btn-block">
  1998.                         <input
  1999.                             type="radio"
  2000.                             name="lead[contractor_type]"
  2001.                             value="Not a Contractor"
  2002.                             required
  2003.                         />
  2004.                         <span>Not a Contractor</span>
  2005.                     </label>
  2006.                     ',
  2007.                     
  2008.                     '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  2009.                     '<div style="text-align: center;">
  2010.                     <button
  2011.                         class="btn mt-3"
  2012.                         type="submit"
  2013.                         style="color: #fff; background: ' $buttonColor ';"
  2014.                     >' $buttonText '</button>
  2015.                     </div>
  2016.                     </form>',
  2017.                 ));
  2018.             }
  2019.             else {
  2020.                 $module implode(" ", array (
  2021.                     "
  2022.                     <div class='row'>
  2023.                         <div class='col-md-12'>
  2024.                             <div class='alert alert-info'>
  2025.                                 <i class='fa fa-info'></i>
  2026.                                 A user account is required to complete this offer. Please sign in or sign up to continue.
  2027.                             </div>
  2028.                         </div>
  2029.                     </div>
  2030.                     <div class='row'>
  2031.                         <div class='col-md-6' style='text-align: right;'>
  2032.                             <a class='button text-white' href='/sign-in'><i class='fa fa-key'></i> Sign In</a>
  2033.                         </div>
  2034.                         <div class='col-md-6' style='text-align: left;'>
  2035.                             <a class='button text-white' href='/sign-up'> Sign Up</a>
  2036.                         </div>
  2037.                     </div>
  2038.                     ",
  2039.                 ));
  2040.             }
  2041.         }
  2042.         elseif($attr["id"] == 1000) { //address etc
  2043.             $module implode(" ", array (
  2044.                 '<form method="post" class="py-4">',
  2045.                 '<label class="btn-block"><span>First Name:</span>
  2046.                     <input
  2047.                         type="text"
  2048.                         class="form-control"
  2049.                         placeholder="Your First Name"
  2050.                         name="lead[firstname]"
  2051.                         required
  2052.                     />
  2053.                 </label>',
  2054.                 '<label class="btn-block"><span>Last Name:</span>
  2055.                     <input
  2056.                         type="text"
  2057.                         class="form-control"
  2058.                         placeholder="Your Last Name"
  2059.                         name="lead[lastname]"
  2060.                         required
  2061.                     />
  2062.                 </label>',
  2063.                 '<label class="btn-block"><span>Address:</span>
  2064.                     <input
  2065.                         type="text"
  2066.                         class="form-control"
  2067.                         placeholder="Your Address"
  2068.                         name="lead[address1]"
  2069.                         required
  2070.                     />
  2071.                 </label>',
  2072.                 '<label class="btn-block"><span>Phone:</span>
  2073.                     <input
  2074.                         type="text"
  2075.                         class="form-control"
  2076.                         placeholder="Your Phone"
  2077.                         name="lead[phone]"
  2078.                         required
  2079.                     />
  2080.                 </label>',
  2081.                 '<label class="btn-block"><span>Email:</span>
  2082.                     <input
  2083.                         type="text"
  2084.                         class="form-control"
  2085.                         placeholder="Your Email Address"
  2086.                         name="lead[email]"
  2087.                         required
  2088.                     />
  2089.                 </label>',
  2090.                 '<label class="btn-block"><span>Type of Contractor:</span></label>
  2091.                 <label class="btn-block">
  2092.                     <input
  2093.                         type="radio"
  2094.                         name="lead[contractor_type]"
  2095.                         value="Primarily Residential"
  2096.                         required
  2097.                     />
  2098.                     <span>Primarily Residential</span>
  2099.                 </label>
  2100.                 <label class="btn-block">
  2101.                     <input
  2102.                         type="radio"
  2103.                         name="lead[contractor_type]"
  2104.                         value="Primarily Commercial"
  2105.                         required
  2106.                     />
  2107.                     <span>Primarily Commercial</span>
  2108.                 </label>
  2109.                 <label class="btn-block">
  2110.                     <input
  2111.                         type="radio"
  2112.                         name="lead[contractor_type]"
  2113.                         value="Both"
  2114.                         required
  2115.                     />
  2116.                     <span>Both</span>
  2117.                 </label>
  2118.                 <label class="btn-block">
  2119.                     <input
  2120.                         type="radio"
  2121.                         name="lead[contractor_type]"
  2122.                         value="Not a Contractor"
  2123.                         required
  2124.                     />
  2125.                     <span>Not a Contractor</span>
  2126.                 </label>',
  2127.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  2128.                 '<div style="text-align: center;">
  2129.                 <button
  2130.                     class="btn mt-3"
  2131.                     type="submit"
  2132.                     style="color: #fff; background: ' $buttonColor ';"
  2133.                 >' $buttonText '</button>
  2134.                 </div>
  2135.                 </form>',
  2136.             ));
  2137.         }
  2138.         elseif($attr["id"] == 83) { //Wil-mar collar
  2139.             $module implode(" ", array (
  2140.                 '<form method="post" class="py-4">',
  2141.                 '<label class="btn-block"><span>First Name:</span>
  2142.                     <input
  2143.                         type="text"
  2144.                         class="form-control"
  2145.                         placeholder="Your First Name"
  2146.                         name="lead[firstname]"
  2147.                         required
  2148.                     />
  2149.                 </label>',
  2150.                 '<label class="btn-block"><span>Last Name:</span>
  2151.                     <input
  2152.                         type="text"
  2153.                         class="form-control"
  2154.                         placeholder="Your Last Name"
  2155.                         name="lead[lastname]"
  2156.                         required
  2157.                     />
  2158.                 </label>',
  2159.                 '<label class="btn-block"><span>Company:</span>
  2160.                     <input
  2161.                         type="text"
  2162.                         class="form-control"
  2163.                         placeholder="Your Company"
  2164.                         name="lead[company]"
  2165.                     />
  2166.                 </label>',
  2167.                 '<label class="btn-block"><span>Address Line 1:</span>
  2168.                     <input
  2169.                         type="text"
  2170.                         class="form-control"
  2171.                         placeholder="Your Address Line 1"
  2172.                         name="lead[address1]"
  2173.                     />
  2174.                 </label>',
  2175.                 '<label class="btn-block"><span>Address Line 2:</span>
  2176.                     <input
  2177.                         type="text"
  2178.                         class="form-control"
  2179.                         placeholder="Your Address Line 2"
  2180.                         name="lead[address2]"
  2181.                     />
  2182.                 </label>',
  2183.                 '<label class="btn-block"><span>City:</span>
  2184.                     <input
  2185.                         type="text"
  2186.                         class="form-control"
  2187.                         placeholder="Your City"
  2188.                         name="lead[city]"
  2189.                     />
  2190.                 </label>',
  2191.                 '<label class="btn-block"><span>State / Region:</span>
  2192.                     <input
  2193.                         type="text"
  2194.                         class="form-control"
  2195.                         placeholder="Your State / Region"
  2196.                         name="lead[state]"
  2197.                     />
  2198.                 </label>',
  2199.                 '<label class="btn-block"><span>Zip Code:</span>
  2200.                     <input
  2201.                         type="text"
  2202.                         class="form-control"
  2203.                         placeholder="Your Zip Code"
  2204.                         name="lead[zip]"
  2205.                     />
  2206.                 </label>',
  2207.                 '<label class="btn-block"><span>Phone:</span>
  2208.                     <input
  2209.                         type="text"
  2210.                         class="form-control"
  2211.                         placeholder="Your Phone"
  2212.                         name="lead[phone]"
  2213.                         required
  2214.                     />
  2215.                 </label>',
  2216.                 '<label class="btn-block"><span>Email:</span>
  2217.                     <input
  2218.                         type="text"
  2219.                         class="form-control"
  2220.                         placeholder="Your Email Address"
  2221.                         name="lead[email]"
  2222.                         required
  2223.                     />
  2224.                 </label>',
  2225.                 '<label class="btn-block"><span>Collar Size?:</span>
  2226.                 <select
  2227.                     class="form-control"
  2228.                     name="lead[collar_size]"
  2229.                     required
  2230.                 >
  2231.                     <option value="">- Select Size -</option>
  2232.                     <option value="3/4 inch">3/4 inch</option>
  2233.                     <option value="1 inch">1 inch</option>
  2234.                     <option value="1 - 1/2 inches">1 - 1/2 inches</option>
  2235.                     <option value="2 inches">2 inches</option>
  2236.                     <option value="3 inches">3 inches</option>
  2237.                     <option value="4 inches">4 inches</option>
  2238.                 </select>
  2239.                 </label>',
  2240.                 '<label class="btn-block"><span>Type of Contractor:</span></label>
  2241.                 <label class="btn-block">
  2242.                     <input
  2243.                         type="radio"
  2244.                         name="lead[contractor_type]"
  2245.                         value="Primarily Residential"
  2246.                         required
  2247.                     />
  2248.                     <span>Primarily Residential</span>
  2249.                 </label>
  2250.                 <label class="btn-block">
  2251.                     <input
  2252.                         type="radio"
  2253.                         name="lead[contractor_type]"
  2254.                         value="Primarily Commercial"
  2255.                         required
  2256.                     />
  2257.                     <span>Primarily Commercial</span>
  2258.                 </label>
  2259.                 <label class="btn-block">
  2260.                     <input
  2261.                         type="radio"
  2262.                         name="lead[contractor_type]"
  2263.                         value="Both"
  2264.                         required
  2265.                     />
  2266.                     <span>Both</span>
  2267.                 </label>
  2268.                 <label class="btn-block">
  2269.                     <input
  2270.                         type="radio"
  2271.                         name="lead[contractor_type]"
  2272.                         value="Not a Contractor"
  2273.                         required
  2274.                     />
  2275.                     <span>Not a Contractor</span>
  2276.                 </label>',
  2277.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  2278.                 '<div style="text-align: center;">
  2279.                 <button
  2280.                     class="btn mt-3"
  2281.                     type="submit"
  2282.                     style="color: #fff; background: ' $buttonColor ';"
  2283.                 >' $buttonText '</button>
  2284.                 </div>
  2285.                 </form>',
  2286.             ));
  2287.         }
  2288.         elseif($attr["id"] == 103789) { //Contractor Exit Strategy
  2289.             $module implode(" ", array (
  2290.                 '<form method="post" class="py-4">',
  2291.                 '<label class="btn-block"><span>First Name:</span>
  2292.                     <input
  2293.                         type="text"
  2294.                         class="form-control"
  2295.                         placeholder="Your First Name"
  2296.                         name="lead[firstname]"
  2297.                         required
  2298.                     />
  2299.                 </label>',
  2300.                 '<label class="btn-block"><span>Last Name:</span>
  2301.                     <input
  2302.                         type="text"
  2303.                         class="form-control"
  2304.                         placeholder="Your Last Name"
  2305.                         name="lead[lastname]"
  2306.                         required
  2307.                     />
  2308.                 </label>',
  2309.                 '<label class="btn-block"><span>Company:</span>
  2310.                     <input
  2311.                         type="text"
  2312.                         class="form-control"
  2313.                         placeholder="Your Company"
  2314.                         name="lead[company]"
  2315.                     />
  2316.                 </label>',
  2317.                 '<label class="btn-block"><span>Address Line 1:</span>
  2318.                     <input
  2319.                         type="text"
  2320.                         class="form-control"
  2321.                         placeholder="Your Address Line 1"
  2322.                         name="lead[address1]"
  2323.                     />
  2324.                 </label>',
  2325.                 '<label class="btn-block"><span>Address Line 2:</span>
  2326.                     <input
  2327.                         type="text"
  2328.                         class="form-control"
  2329.                         placeholder="Your Address Line 2"
  2330.                         name="lead[address2]"
  2331.                     />
  2332.                 </label>',
  2333.                 '<label class="btn-block"><span>City:</span>
  2334.                     <input
  2335.                         type="text"
  2336.                         class="form-control"
  2337.                         placeholder="Your City"
  2338.                         name="lead[city]"
  2339.                     />
  2340.                 </label>',
  2341.                 '<label class="btn-block"><span>State / Region:</span>
  2342.                     <input
  2343.                         type="text"
  2344.                         class="form-control"
  2345.                         placeholder="Your State / Region"
  2346.                         name="lead[state]"
  2347.                     />
  2348.                 </label>',
  2349.                 '<label class="btn-block"><span>Zip Code:</span>
  2350.                     <input
  2351.                         type="text"
  2352.                         class="form-control"
  2353.                         placeholder="Your Zip Code"
  2354.                         name="lead[zip]"
  2355.                     />
  2356.                 </label>',
  2357.                 '<label class="btn-block"><span>Phone:</span>
  2358.                     <input
  2359.                         type="text"
  2360.                         class="form-control"
  2361.                         placeholder="Your Phone"
  2362.                         name="lead[phone]"
  2363.                         required
  2364.                     />
  2365.                 </label>',
  2366.                 '<label class="btn-block"><span>Email:</span>
  2367.                     <input
  2368.                         type="text"
  2369.                         class="form-control"
  2370.                         placeholder="Your Email Address"
  2371.                         name="lead[email]"
  2372.                         required
  2373.                     />
  2374.                 </label>',
  2375.                 '<label class="btn-block"><span>Type of Contractor:</span></label>
  2376.                 <label class="btn-block">
  2377.                     <input
  2378.                         type="radio"
  2379.                         name="lead[contractor_type]"
  2380.                         value="Primarily Residential"
  2381.                         required
  2382.                     />
  2383.                     <span>Primarily Residential</span>
  2384.                 </label>
  2385.                 <label class="btn-block">
  2386.                     <input
  2387.                         type="radio"
  2388.                         name="lead[contractor_type]"
  2389.                         value="Primarily Commercial"
  2390.                         required
  2391.                     />
  2392.                     <span>Primarily Commercial</span>
  2393.                 </label>
  2394.                 <label class="btn-block">
  2395.                     <input
  2396.                         type="radio"
  2397.                         name="lead[contractor_type]"
  2398.                         value="Both"
  2399.                         required
  2400.                     />
  2401.                     <span>Both</span>
  2402.                 </label>
  2403.                 <label class="btn-block">
  2404.                     <input
  2405.                         type="radio"
  2406.                         name="lead[contractor_type]"
  2407.                         value="Not a Contractor"
  2408.                         required
  2409.                     />
  2410.                     <span>Not a Contractor</span>
  2411.                 </label>',
  2412.                 '<label class="btn-block"><span>Years in Business:</span>
  2413.                     <input
  2414.                         type="text"
  2415.                         class="form-control"
  2416.                         placeholder="Years in Business"
  2417.                         name="lead[years_in_business]"
  2418.                         required
  2419.                     />
  2420.                 </label>',
  2421.                 '<label class="btn-block"><span>Approximate Number of Field Crew (height of the season):</span>
  2422.                     <input
  2423.                         type="text"
  2424.                         class="form-control"
  2425.                         placeholder="Number of Field Crew"
  2426.                         name="lead[num_field_crew]"
  2427.                         required
  2428.                     />
  2429.                 </label>',
  2430.                 '<label class="btn-block"><span>Annual Revenue:</span>
  2431.                     <input
  2432.                         type="text"
  2433.                         class="form-control"
  2434.                         placeholder="Annual Revenue"
  2435.                         name="lead[annual_revenue]"
  2436.                         required
  2437.                     />
  2438.                 </label>',
  2439.                 '<label class="btn-block"><span>Self-Perform Trade (Your own crews?):</span>
  2440.                     <input
  2441.                         type="text"
  2442.                         class="form-control"
  2443.                         placeholder="Self-Perform Trade"
  2444.                         name="lead[self_perform_trade]"
  2445.                         required
  2446.                     />
  2447.                 </label>',
  2448.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  2449.                 '<div style="text-align: center;">
  2450.                 <button
  2451.                     class="btn mt-3"
  2452.                     type="submit"
  2453.                     style="color: #fff; background: ' $buttonColor ';"
  2454.                 >' $buttonText '</button>
  2455.                 </div>
  2456.                 </form>',
  2457.             ));
  2458.         }
  2459.         else {
  2460.             $module implode(" ", array (
  2461.                 '<form method="post" class="py-4">',
  2462.                 '<label class="btn-block"><span>First Name:</span>
  2463.                     <input
  2464.                         type="text"
  2465.                         class="form-control"
  2466.                         placeholder="Your First Name"
  2467.                         name="lead[firstname]"
  2468.                         required
  2469.                     />
  2470.                 </label>',
  2471.                 '<label class="btn-block"><span>Last Name:</span>
  2472.                     <input
  2473.                         type="text"
  2474.                         class="form-control"
  2475.                         placeholder="Your Last Name"
  2476.                         name="lead[lastname]"
  2477.                         required
  2478.                     />
  2479.                 </label>',
  2480.                 '<label class="btn-block"><span>Company:</span>
  2481.                     <input
  2482.                         type="text"
  2483.                         class="form-control"
  2484.                         placeholder="Your Company"
  2485.                         name="lead[company]"
  2486.                     />
  2487.                 </label>',
  2488.                 '<label class="btn-block"><span>Address Line 1:</span>
  2489.                     <input
  2490.                         type="text"
  2491.                         class="form-control"
  2492.                         placeholder="Your Address Line 1"
  2493.                         name="lead[address1]"
  2494.                     />
  2495.                 </label>',
  2496.                 '<label class="btn-block"><span>Address Line 2:</span>
  2497.                     <input
  2498.                         type="text"
  2499.                         class="form-control"
  2500.                         placeholder="Your Address Line 2"
  2501.                         name="lead[address2]"
  2502.                     />
  2503.                 </label>',
  2504.                 '<label class="btn-block"><span>City:</span>
  2505.                     <input
  2506.                         type="text"
  2507.                         class="form-control"
  2508.                         placeholder="Your City"
  2509.                         name="lead[city]"
  2510.                     />
  2511.                 </label>',
  2512.                 '<label class="btn-block"><span>State / Region:</span>
  2513.                     <input
  2514.                         type="text"
  2515.                         class="form-control"
  2516.                         placeholder="Your State / Region"
  2517.                         name="lead[state]"
  2518.                     />
  2519.                 </label>',
  2520.                 '<label class="btn-block"><span>Zip Code:</span>
  2521.                     <input
  2522.                         type="text"
  2523.                         class="form-control"
  2524.                         placeholder="Your Zip Code"
  2525.                         name="lead[zip]"
  2526.                     />
  2527.                 </label>',
  2528.                 '<label class="btn-block"><span>Phone:</span>
  2529.                     <input
  2530.                         type="text"
  2531.                         class="form-control"
  2532.                         placeholder="Your Phone"
  2533.                         name="lead[phone]"
  2534.                         required
  2535.                     />
  2536.                 </label>',
  2537.                 '<label class="btn-block"><span>Email:</span>
  2538.                     <input
  2539.                         type="text"
  2540.                         class="form-control"
  2541.                         placeholder="Your Email Address"
  2542.                         name="lead[email]"
  2543.                         required
  2544.                     />
  2545.                 </label>',
  2546.                 '<label class="btn-block"><span>Type of Contractor:</span></label>
  2547.                 <label class="btn-block">
  2548.                     <input
  2549.                         type="radio"
  2550.                         name="lead[contractor_type]"
  2551.                         value="Primarily Residential"
  2552.                         required
  2553.                     />
  2554.                     <span>Primarily Residential</span>
  2555.                 </label>
  2556.                 <label class="btn-block">
  2557.                     <input
  2558.                         type="radio"
  2559.                         name="lead[contractor_type]"
  2560.                         value="Primarily Commercial"
  2561.                         required
  2562.                     />
  2563.                     <span>Primarily Commercial</span>
  2564.                 </label>
  2565.                 <label class="btn-block">
  2566.                     <input
  2567.                         type="radio"
  2568.                         name="lead[contractor_type]"
  2569.                         value="Both"
  2570.                         required
  2571.                     />
  2572.                     <span>Both</span>
  2573.                 </label>
  2574.                 <label class="btn-block">
  2575.                     <input
  2576.                         type="radio"
  2577.                         name="lead[contractor_type]"
  2578.                         value="Not a Contractor"
  2579.                         required
  2580.                     />
  2581.                     <span>Not a Contractor</span>
  2582.                 </label>',
  2583.                 '<div class="form-row g-recaptcha" data-sitekey="6LeEIlMUAAAAAGhdmJJLdJHPxaWx2GqBjber5n6B"></div>',
  2584.                 '<div style="text-align: center;">
  2585.                 <button
  2586.                     class="btn mt-3"
  2587.                     type="submit"
  2588.                     style="color: #fff; background: ' $buttonColor ';"
  2589.                 >' $buttonText '</button>
  2590.                 </div>
  2591.                 </form>',
  2592.             ));
  2593.         }
  2594.         return $module;
  2595.     }
  2596.     protected function getSymfonyForm ($attr = array ())
  2597.     {
  2598.     }
  2599.     protected function getContent ($attr = array ())
  2600.     {
  2601.         $html ""//HTML to be returned
  2602.         
  2603.         try {
  2604.             $type = empty($attr["type"]) ? "*" $attr["type"];
  2605.             $category = empty($attr["category"]) ? "*" $attr["category"];
  2606.             $order = empty($attr["order"]) ? "" $attr["order"];
  2607.             $dir = empty($attr["dir"]) ? "" $attr["dir"];
  2608.             $page = empty($_GET["p"]) ? : (int) $_GET["p"];
  2609.             $limit = isset($attr["limit"]) ? $attr["limit"] : 0;
  2610.             $use_secondary_categories = isset($attr["use_secondary_categories"]) ? $attr["use_secondary_categories"] : false;
  2611.             $members_only = isset($attr["members_only"]) ? $attr["members_only"] : false;
  2612.             $allowDupes = isset($attr["dupes"]) ? (strtolower($attr["dupes"]) === "yes") : false;
  2613.             $excludeInDupes = isset($attr["exclude_in_dupes"]) ? (strtolower($attr["exclude_in_dupes"]) === "yes") : false;
  2614.             $as_gallery = isset($attr["as_gallery"]) ? (strtolower($attr["as_gallery"]) === "yes") : false;
  2615.             $only_featured = isset($attr["only_featured"]) ? (strtolower($attr["only_featured"]) === "yes") : false;
  2616.             $only_announcements = isset($attr["only_announcements"]) ? (strtolower($attr["only_announcements"]) === "yes") : false;
  2617.             $customer_level_or_higher = isset($attr["customer_level_or_higher"]) ? $attr["customer_level_or_higher"] : false;
  2618.             $site_override = isset($attr["site"]) ? $attr["site"] : false;
  2619.             //$cache_test = $cache_time ? true : false;
  2620.             //$display_no_content_message = isset($attr["display_no_content_message"]) ? $attr["display_no_content_message"] : false;
  2621.             $no_content_message = isset($attr["no_content_message"]) ? $attr["no_content_message"] : "";
  2622.             
  2623.             if (!empty($attr["links"]) && is_string($attr["links"])) {
  2624.                 $attr["links"] = array_map('trim'explode(","$attr["links"]));
  2625.             }
  2626.             $content $this->contentHelper->getContent(
  2627.                 $type,
  2628.                 $category,
  2629.                 $order,
  2630.                 $dir,
  2631.                 $page,
  2632.                 $limit,
  2633.                 $allowDupes,
  2634.                 "*",
  2635.                 $use_secondary_categories,
  2636.                 $members_only,
  2637.                 $as_gallery//require a featured image
  2638.                 $only_featured,
  2639.                 "",
  2640.                 $customer_level_or_higher,
  2641.                 $only_announcements,
  2642.                 $excludeInDupes,
  2643.                 $site_override
  2644.             );
  2645.             if($this->request) {
  2646.                 
  2647.                 if(preg_match('/bot|crawl|curl|dataprovider|search|get|spider|find|java|majesticsEO|google|yahoo|teoma|contaxe|yandex|libwww-perl|sleuth|audit|robot|Node|seo|broken|buck|Anthill|facebookexternalhit/i'$this->request->headers->get("User-Agent"))) {
  2648.                     $this->contentHelper->addImpressions($this->request$content["content"]);
  2649.                 }
  2650.                 else {
  2651.                     $this->contentHelper->enqueueImpressions($this->request$content["content"]);
  2652.                 }
  2653.                 
  2654.             }
  2655.             
  2656.             $cache_time = isset($attr["cache_time"]) ? (int) $attr["cache_time"] : 0;
  2657.             if($cache_time) {
  2658.                 $cache = new FilesystemAdapter();
  2659.                 
  2660.                 $env $this->container->getParameter('kernel.environment');
  2661.                 
  2662.                 $site_code "";
  2663.                 $request $this->request;
  2664.                 if($request) {
  2665.                     $session $request->getSession();
  2666.                     if($session) {
  2667.                         $site_code $session->get("site");
  2668.                     }
  2669.                 }
  2670.                 
  2671.                 $cache_item $cache->getItem($site_code $env str_replace(['{','}','(',')','/','\\','@',':''"'], ""__METHOD__ serialize(func_get_args())));
  2672.                 if($cache_item->isHit()) {
  2673.                     $results $cache_item->get();
  2674.                     return $results;
  2675.                 }
  2676.             }
  2677.             $attr["data"] = $content["content"];
  2678.             $attr["total"] = $content["total"];
  2679.             $attr["page"] = $page;
  2680.             /*
  2681.             if($type == 8) {
  2682.                 $attr["media"] = [];
  2683.                 foreach($content["content"] as $c) {
  2684.                     $cm = $c->getContentMetaByKey("webinar_showgraphic");
  2685.                     if(is_null($cm)) {
  2686.                         $attr["media"][] = "";
  2687.                     }
  2688.                     else {
  2689.                         $m = $this->mediaHelper->getMediaByOldId($cm->getMetavalue());
  2690.                         $attr["media"][] = $m;
  2691.                     }
  2692.                 }
  2693.             }
  2694.             */
  2695.             // convert the content into a module
  2696.             if($type == || $type == || $as_gallery) {
  2697.                 if($type == 4) {
  2698.                     $attr["class"] = isset($attr["class"]) ? $attr["class"] . " directory" "directory";
  2699.                 }
  2700.                 $attr["class"] = isset($attr["class"]) ? $attr["class"] . " gallery" "gallery";
  2701.                 $attr["columns"] = isset($attr["columns"]) ? $attr["columns"] : 3;
  2702.                 $attr["mitems"] = "";
  2703.                 $tmpl $this->twig->load("modules/gallery-display.html.twig");
  2704.             }
  2705.             else {
  2706.                 $tmpl $this->twig->load("modules/default-loop.html.twig");
  2707.             }
  2708.             
  2709.             //if($attr["total"] > 0) {
  2710.                 $html $tmpl->render(array(
  2711.                     "module" => $attr,
  2712.                 ));
  2713.                 
  2714.                 if($cache_time) {
  2715.                     $cache_item->set($html);
  2716.                     $cache_item->expiresAfter($cache_time);
  2717.                     $cache->save($cache_item);
  2718.                 }
  2719.             //}
  2720.             
  2721.         }
  2722.         catch (\Exception $e) {
  2723.             var_dump("File: "$e->getFile());
  2724.             var_dump("Line: "$e->getLine());
  2725.             var_dump($e->getMessage());
  2726.             exit;
  2727.         }
  2728.         
  2729.         return $html;
  2730.     }
  2731.     
  2732.     protected function getAds($attr = array ()) {
  2733.         
  2734.         $position = empty($attr["position"]) ? "" $attr["position"];
  2735.         
  2736.         $site_code 1;
  2737.         $request $this->request;
  2738.         if($request) {
  2739.             $session $request->getSession();
  2740.             if($session) {
  2741.                 $site_code $session->get("site");
  2742.             }
  2743.         }
  2744.         
  2745.         //Only set up for the poll ad section at the moment.
  2746.         //Update if we need to pull other ad types / add specific options.
  2747.         if($position == "ad-poll") {
  2748.             $mediaGroup $this->mediaHelper->getMediaGroupByPosition($attr["position"]);
  2749.             $ads $mediaGroup->getActiveMediaGroupItemsBySiteId($site_code);
  2750.             if(empty($ads)) {
  2751.                 return "";
  2752.             }
  2753.             shuffle($ads);
  2754.             $ad $ads[0];
  2755.             
  2756.             $adHtml "";
  2757.             $adHtml .= "<h3 class='module-title' style='margin: 0 0 0.8rem 0;text-transform: unset;'>" strtoupper(SiteConfig::CONFIGS[$site_code]["site_code"]) . " Poll brought to you by:</h3>";
  2758.             $adHtml .= "<div style='text-align:center;'>";
  2759.             $adHtml .= $ad->getMediaImageTag("""");
  2760.             $adHtml .= "</div>";
  2761.             
  2762.             return $adHtml;
  2763.         }
  2764.         
  2765.     }
  2766.     
  2767.     protected function getMediaGroup ($attr = array ())
  2768.     {
  2769.         $attr array_merge([
  2770.             "columns" => 3,
  2771.             "limit" => "",
  2772.             "class" => ""
  2773.         ], $attr);
  2774.         
  2775.         $data $this->mediaHelper->getMediaGroupByPosition($attr["position"]);
  2776.         $attr["data"] = $data;
  2777.         $temp_items null;
  2778.         $site_code "";
  2779.         if($data->isAdGroup()) {
  2780.             $request $this->request;
  2781.             if($request) {
  2782.                 $session $request->getSession();
  2783.                 if($session) {
  2784.                     $site_code $session->get("site");
  2785.                     //$temp_items = $data->getMediaGroupItemsBySiteId($site_code);
  2786.                 }
  2787.             }
  2788.         }
  2789.         
  2790.         $limit $attr["limit"] ? $attr["limit"] : $data->getDisplayLimit();
  2791.         $attr["items"] = $this->mediaHelper->getRandomMediaGroupItems($data$limit$site_code);
  2792.         
  2793.         
  2794.         //$temp_items = $data->getMediaGroupItems()->toArray();
  2795.         //shuffle($temp_items);
  2796.         //$attr["items"] = $attr["limit"] ? array_slice($temp_items, 0, $attr["limit"]) : $temp_items;
  2797.         
  2798.         
  2799.         $tmpl $this->twig->load("elements/media-group-v2.html.twig");
  2800.         $html $tmpl->render(array(
  2801.             "module" => $attr,
  2802.             /*
  2803.             "attr" => $attrs,
  2804.             "mediagroup" => $module,
  2805.             */
  2806.         ));
  2807.         
  2808.         return $html;
  2809.     }
  2810.     
  2811.     
  2812.     protected function getGallery2 ($attr = array ())
  2813.     {
  2814.         $attr array_merge([
  2815.             "columns" => 3,
  2816.             "link" => "file",
  2817.             "ids" => [],
  2818.             "links" => [],
  2819.             "idtype" => "",
  2820.             "limit" => ""
  2821.         ], $attr);
  2822.         
  2823.         $attr["class"] = !empty($attr["class"]) ? $attr["class"] . " gallery" "gallery";
  2824.         if (!empty($attr["ids"]) && is_string($attr["ids"])) {
  2825.             $attr["ids"] = explode(","$attr["ids"]);
  2826.         }
  2827.         
  2828.         if (!empty($attr["links"]) && is_string($attr["links"])) {
  2829.             $attr["links"] = array_map('trim'explode(","$attr["links"]));
  2830.         }
  2831.         
  2832.         $limit = (int) $attr["limit"];
  2833.         $data = array ();
  2834.         foreach ($attr["ids"] as $id) {
  2835.             try {
  2836.                 if($attr["idtype"] == "old") {
  2837.                     $media $this->mediaHelper->getMediaByOldId($id);
  2838.                 }
  2839.                 else {
  2840.                     $media $this->mediaHelper->getMediaById($id);
  2841.                 }
  2842.                 
  2843.                 $data[] = $media;
  2844.             } catch (\Exception $e) {
  2845.                 // ignore
  2846.             }
  2847.         }
  2848.         
  2849.         if($limit && $limit count($data)) {
  2850.             $rand $this->getUniqueRandomNumbers(0count($data)-1$limit);
  2851.             $links = array();
  2852.             $attr["data"] = array();
  2853.             foreach($rand as $r) {
  2854.                 $attr["data"][] = $data[$r];
  2855.                 $links[] = $attr["links"][$r];
  2856.             }
  2857.             $attr["links"] = $links;
  2858.         }
  2859.         else {
  2860.             $attr["data"] = $data;
  2861.         }
  2862.         
  2863.         $tmpl $this->twig->load("modules/gallery-display.html.twig");
  2864.         $html $tmpl->render(array(
  2865.             "module" => $attr,
  2866.         ));
  2867.         
  2868.         return $html;
  2869.         
  2870.     }
  2871.     
  2872.     protected function getTweets ($attr = array ())
  2873.     {
  2874.         $page = empty($attr["page"]) ? "" $attr["page"];
  2875.         $limit = empty($attr["limit"]) ? "" $attr["limit"];
  2876.         
  2877.         $module implode(" ", array (
  2878.             "<a class='twitter-timeline'
  2879.                   href='https://twitter.com/{$page}'
  2880.                   data-tweet-limit='{$limit}'>
  2881.             Tweets by @{$page}</a>",
  2882.             "<script async src='https://platform.twitter.com/widgets.js'></script>",
  2883.         ));
  2884.         
  2885.         return $module;
  2886.     }
  2887.     protected function getFBPost ($attr = array ())
  2888.     {
  2889.         $page = empty($attr["fbpage"]) ? "" $attr["fbpage"];
  2890.         $width = empty($attr["width"]) ? "408px" $attr["width"];
  2891.         $height = empty($attr["height"]) ? "1054px" $attr["height"];
  2892.         $rcs "https%3A%2F%2Fwww.facebook.com%2Frooferscoffeeshop";
  2893.         $aar "https%3A%2F%2Fwww.facebook.com%2FAskARooferRCS";
  2894.         $mcs "https%3A%2F%2Fwww.facebook.com%2FMetalcoffeeshop";
  2895.         $ccs "https%3A%2F%2Fwww.facebook.com%2FCoatingsCoffeeShop";
  2896.         switch ($page) {
  2897.             case "rcs":
  2898.                 $fbPage $rcs;
  2899.                 break;
  2900.             case "aar":
  2901.                 $fbPage $aar;
  2902.                 break;
  2903.             case "mcs":
  2904.                 $fbPage $mcs;
  2905.                 break;
  2906.             case "ccs":
  2907.                 $fbPage $ccs;
  2908.                 break;
  2909.             default:
  2910.                 $fbPage $rcs;
  2911.         }
  2912.         $module implode(" ", array (
  2913.             "<iframe id='FBiframe' src='https://www.facebook.com/plugins/page.php?href=$fbPage&tabs=timeline&small_header=true&adapt_container_width=true&width=$width&height=$height&hide_cover=true&show_facepile=true&appId=339799721874547' width=$width height=$height style='border:none;overflow:hidden' scrolling='no' frameborder='0' allowfullscreen='true' allow='autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share'></iframe>"
  2914.         ));
  2915.         return $module;
  2916.     }
  2917.     
  2918.     protected function getPoll ($attr = array ())
  2919.     {
  2920.         
  2921.         $site_code "";
  2922.         $request $this->request;
  2923.         if($request) {
  2924.             $session $request->getSession();
  2925.             if($session) {
  2926.                 $site_code $session->get("site");
  2927.             }
  2928.         }
  2929.         $id = empty($attr["id"]) ? "" $attr["id"];
  2930.         $directory = isset($attr["directory"]) ? (strtolower($attr["directory"]) === "yes") : false;
  2931.         if($id) {
  2932.             $poll $this->pollHelper->getPollById($id);
  2933.         }
  2934.         else {
  2935.             $poll $this->pollHelper->getActivePoll();
  2936.         }
  2937.         if(!$poll) {
  2938.             return "";
  2939.         }
  2940.         $this->pollHelper->incrementPollImpressions($poll);
  2941.         
  2942.         $allowSubmission 0;
  2943.         $userId 0;
  2944.         $signInForm "";
  2945.         $user $this->security->getUser();
  2946.         if($user) {
  2947.             $userId $user->getId();
  2948.             $allowSubmission 1;
  2949.         }
  2950.         elseif(!$poll->getRequiresLogin()) {
  2951.             $allowSubmission 1;
  2952.         }
  2953.         else {
  2954.             $signInForm implode(" ", [
  2955.                 "<div class='mod mod-sign-in'>",
  2956.                     "<form method='post' action='/catch-all'>",
  2957.                         "<input type='hidden' name='action' value='sign-in' />",
  2958.                         "<input type='hidden' name='redirectPath' value='/' />",
  2959.                         "<p>Please sign into your RoofersCoffeeShop Account to take the poll or see the results.</p>",
  2960.                         "<label class='btn-block'><span>Username</span>",
  2961.                             "<input",
  2962.                                 "class='form-control'",
  2963.                                 "type='text'",
  2964.                                 "name='username'",
  2965.                                 "placeholder='Your Username'",
  2966.                                 "required",
  2967.                             "/>",
  2968.                         "</label>",
  2969.                         "<label class='btn-block'><span>Password</span>",
  2970.                             "<input",
  2971.                                 "class='form-control'",
  2972.                                 "type='password'",
  2973.                                 "name='password'",
  2974.                                 "placeholder='Your Password'",
  2975.                                 "required",
  2976.                             "/>",
  2977.                         "</label>",
  2978.                         "<button",
  2979.                             "class='btn btn-secondary'",
  2980.                             "type='submit'",
  2981.                         ">Sign In</button>",
  2982.                     "</form>",
  2983.                 "</div>",
  2984.                 "<hr />",
  2985.                 "<center><a href='/sign-up' style='color:#d11818;'>Need an account? Create one here.</a></center>",
  2986.             ]);
  2987.         }
  2988.         
  2989.         $ad $poll->getAd();
  2990.         $adHtml "";
  2991.         $useSlider false;
  2992.         $sliderHtml "";
  2993.         if($directory) {
  2994.             $ad $poll->getPopOutAd();
  2995.             /*$adHtml = $ad->getDescription();
  2996.             if($adHtml) {
  2997.                 $adHtml = $adHtml;
  2998.             }
  2999.             else {
  3000.                 $adHtml = "<h3>Thank you for your feedback!</h3>";
  3001.             }*/
  3002.             if($ad && $ad->getQuestionSlider()) {
  3003.                 $useSlider true;
  3004.                 $sliderHtml str_replace(array("\r""\n"), ''
  3005.                 '<div class=\"col-md-7\">
  3006.                     <div id=\"part1\" style=\"margin-top:25px;\">
  3007.                         <p>How likely are you to recommend us to a friend or colleague?</p>
  3008.                         <p><input id=\"pi_input\" type=\"range\" class=\"slider\" min=\"1\" max=\"10\" step=\"1\" style=\"width:100%;\"/></p>
  3009.                         <div  class=\"row\">
  3010.                             <div class=\"col-md-6\" style=\"font-size:16px;padding-left:40px;\">
  3011.                                 Rating: <output id=\"value\"></output>
  3012.                             </div>
  3013.                             <div class=\"col-md-6\">
  3014.                                 <input type=\"buttom\" class=\"button\" value=\"Submit\" id=\"popSubmit\" style=\"width:100px;\">
  3015.                             </div>
  3016.                         </div>
  3017.                     </div>
  3018.                     <div id=\"part2\" style=\"display:none\">
  3019.                         <div style=\"margin-top:50px;\">
  3020.                             <h3>Thank you for your feedback!</h3>
  3021.                             <p>Visit the <a href=\"/our-directory\">RCS Directory</a> to see more from our partners!</p>
  3022.                         </div>
  3023.                     </div>
  3024.                 </div>');
  3025.             }
  3026.             $adHtml "Thank you for your feedback!";
  3027.             $ad $poll->getAd();
  3028.         }
  3029.         elseif($ad) {
  3030.             //$adHtml .= "<div class='ad-sidebar'>";
  3031.             //$adHtml .= "<div class='media-block'>";
  3032.             $adHtml .= "<h3 class='module-title' style='margin: 0 0 0.8rem 0;text-transform: unset;'>" strtoupper(SiteConfig::CONFIGS[$site_code]["site_code"]) . " brought to you by:</h3>";
  3033.             $adHtml .= "<div style='text-align:center;'>";
  3034.             $adHtml .= $ad->getMediaImageTag("""");
  3035.             $adHtml .= "</div>";
  3036.             //$adHtml .= "</div>";
  3037.             //$adHtml .= "</div>";
  3038.             $adHtml preg_replace"/\r|\n/"""$adHtml );
  3039.         }
  3040.         
  3041.         ob_start();
  3042.         ?>
  3043.         <link href="/assets/css/surveyjs-custom.min.css?v=11-22-22" rel="stylesheet" />
  3044.         <?php if(!$directory) : ?>
  3045.             <h3 class="module-title" style="margin:0"><?php echo strtoupper(SiteConfig::CONFIGS[$site_code]["site_code"]) ?> Poll</h3>
  3046.         <?php endif; ?>
  3047.         <div id="poll-image-container" class="poll-image-container">
  3048.         <?php 
  3049.         $afterPollHtml "";
  3050.         if($poll->getMedia()) {
  3051.             if($poll->getInfoUrl()) {
  3052.                 $afterPollHtml "<a href='{$poll->getInfoUrl()}' class='button poll-button text-white' target='_blank'>Continue the Conversation</a>";
  3053.                 echo "<a href='{$poll->getInfoUrl()}' target='_blank'>";
  3054.             }
  3055.             echo $poll->getMedia()->getImageTag();
  3056.             if($poll->getInfoUrl()) {
  3057.                 echo "</a>";
  3058.             }
  3059.         }
  3060.         ?>
  3061.         </div>
  3062.         
  3063.         <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js" integrity="sha512-d9xgZrVZpmmQlfonhQUvTR7lMPtO7NkZMkA0ABN3PHCbKA5nqylQ/yWlFAyY6hYgdF1Qh6nYiuADWwKB4C2WSw==" crossorigin="anonymous"></script>
  3064.         <script>
  3065.         function renderPoll(data) {
  3066.             
  3067.             var adHtml = "<?=$adHtml?>";
  3068.             var directory = "<?=$directory?>";
  3069.             var useSlider = "<?=$useSlider?>";
  3070.             if(adHtml) {
  3071.                 if(directory) {
  3072.                     $("#home-poll").html($("#pollReplacementAd").html());
  3073.                     $('#poa-container').height($('#rc-center').height());
  3074.                 }
  3075.                 else {
  3076.                     setTimeout(function () {
  3077.                         $("#home-poll").fadeOut("500", function() {
  3078.                             $("#home-poll").html(adHtml);
  3079.                             $("#home-poll").fadeIn("500");
  3080.                         });
  3081.                     }, 5000);
  3082.                 }
  3083.             }
  3084.             $("#pollLoadingContainer").html("");
  3085.             $("#poll-image-container").html("");
  3086.             $("#beforePoll").html(<?=json_encode($poll->getTitle())?>);
  3087.             $("#beforePoll").show();
  3088.             $("#afterPoll").html("<?=$afterPollHtml?>");
  3089.             $("#afterPoll").show();
  3090.             $("#pollResults").show();
  3091.             
  3092.             var keys = [];
  3093.             var vals = [];
  3094.             for(var k in data) {
  3095.                 keys.push(k);
  3096.                 vals.push(data[k]);
  3097.             }
  3098.             console.log("DATA");
  3099.             console.log(data);
  3100.             var ctx = document.getElementById('pollResults').getContext('2d');
  3101.             var pollResults = new Chart(ctx, {
  3102.                 //type: 'bar',
  3103.                 type: 'horizontalBar',
  3104.                 data: {
  3105.                     //labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
  3106.                     labels: keys,
  3107.                     datasets: [{
  3108.                         label: '# of Votes',
  3109.                         //data: [12, 19, 3, 5, 2, 3],
  3110.                         data: vals,
  3111.                         backgroundColor: [
  3112.                             'rgba(255, 99, 132, 0.4)',
  3113.                             'rgba(54, 162, 235, 0.4)',
  3114.                             'rgba(255, 206, 86, 0.4)',
  3115.                             'rgba(75, 192, 192, 0.4)',
  3116.                             'rgba(153, 102, 255, 0.4)',
  3117.                             'rgba(255, 159, 64, 0.4)'
  3118.                         ],
  3119.                         borderColor: [
  3120.                             'rgba(255, 99, 132, 1)',
  3121.                             'rgba(54, 162, 235, 1)',
  3122.                             'rgba(255, 206, 86, 1)',
  3123.                             'rgba(75, 192, 192, 1)',
  3124.                             'rgba(153, 102, 255, 1)',
  3125.                             'rgba(255, 159, 64, 1)'
  3126.                         ],
  3127.                         borderWidth: 1
  3128.                     }]
  3129.                 },
  3130.                 options: {
  3131.                     legend: {
  3132.                         display: false
  3133.                     },
  3134.                     scales: {
  3135.                         yAxes: [{
  3136.                             ticks: {
  3137.                                 beginAtZero: true
  3138.                             }
  3139.                         }],
  3140.                         xAxes: [{
  3141.                             ticks: {
  3142.                                 beginAtZero: true
  3143.                             }
  3144.                         }]
  3145.                     }
  3146.                 }
  3147.             });
  3148.             
  3149.         }
  3150.         </script>
  3151.         <?php
  3152.         $module ob_get_clean();
  3153.         
  3154.         $responsesOpen $this->pollHelper->areResponsesOpen($poll);
  3155.         $userCompleted $this->pollHelper->hasUserCompletedPoll($user$poll);
  3156.         $cookieCompleted $this->request->cookies->get("poll" $poll->getId());
  3157.         
  3158.         if($userCompleted || !$responsesOpen || $cookieCompleted) {
  3159.             
  3160.             //Instead of poll results, display an ad for some reason:
  3161.             if($directory) {
  3162.                 $ad $poll->getPopOutAd();
  3163.                 $adHtml $ad->getDescription();
  3164.                 if($adHtml) {
  3165.                     return $adHtml;
  3166.                 }
  3167.                 return "<h3>Thank you for your feedback!</h3>";
  3168.             }
  3169.             elseif($ad) {
  3170.                 return $adHtml;
  3171.             }
  3172.             else {
  3173.                 $results $this->pollHelper->getPollResults($poll->getId());
  3174.                 $results json_encode($results);
  3175.                 
  3176.                 $module .= "<div id='pollLoadingContainer'><div id='pollLoader'></div></div>";
  3177.                 $module .= "<div id='beforePoll'></div><canvas id='pollResults' width='400' height='300'></canvas><div id='afterPoll'></div>";
  3178.                 $module .= "<script>
  3179.                 console.log('RESULTS');
  3180.                 console.log($results);
  3181.                 renderPoll($results);</script>";
  3182.                 return $module;
  3183.             }
  3184.         }
  3185.         
  3186.         $choicesJSArray "[";
  3187.         foreach($poll->getActivePollOptionsArray() as $key => $value) {
  3188.             $value addslashes($value);
  3189.             $choicesJSArray .= "{'value': '{$key}', 'text': '{$value}'},";
  3190.         }
  3191.         $choicesJSArray .= "]";
  3192.         
  3193.         ob_start();
  3194.         ?>
  3195.         
  3196.         <!--<script src='https://unpkg.com/survey-jquery'></script>-->
  3197.         <script src='https://unpkg.com/survey-jquery@1.9.120/survey.jquery.js'></script>
  3198.         <!--<link href='https://unpkg.com/survey-jquery/survey.min.css' type='text/css' rel='stylesheet'/>-->
  3199.         <link href='https://unpkg.com/survey-jquery@1.9.120/survey.min.css' type='text/css' rel='stylesheet'/>
  3200.         <div id='surveyContainer'></div>
  3201.         <script>
  3202.         var useSlider = "<?=$useSlider?>";
  3203.         /*var sliderHtml = "< ?=$sliderHtml?>";*/
  3204.         //if(<?=$ad && $ad->getQuestionSlider()?>) {
  3205.         if(useSlider) {
  3206.             /*
  3207.             Having issues with the slider:
  3208.             var surveyJSON = {
  3209.                 showTitle: false,
  3210.                 completeText: 'Submit',
  3211.                 requiredText: '',
  3212.                 focusFirstQuestionAutomatic: false,
  3213.                 pages:
  3214.                 [
  3215.                     {
  3216.                         name:'page1',
  3217.                         questions:
  3218.                         [
  3219.                             {
  3220.                                 type: 'html',
  3221.                                 name: 'question',
  3222.                                 html: sliderHtml
  3223.                             }
  3224.                         ]
  3225.                     }
  3226.                 ]
  3227.             };
  3228.             */
  3229.             var surveyJSON = {
  3230.                 showTitle: false,
  3231.                 completeText: 'Submit',
  3232.                 requiredText: '',
  3233.                 focusFirstQuestionAutomatic: false,
  3234.                 pages:
  3235.                 [
  3236.                     {
  3237.                         name:'page1',
  3238.                         questions:
  3239.                         [
  3240.                             {
  3241.                                 type: 'rating',
  3242.                                 autoGenerate: false,
  3243.                                 rateCount: 10,
  3244.                                 rateValues: <?=$choicesJSArray?>,
  3245.                                 "rateMax": 10,
  3246.                                 isRequired: true,
  3247.                                 name: 'question',
  3248.                                 title: <?=json_encode($poll->getTitle())?>
  3249.                             }
  3250.                         ]
  3251.                     }
  3252.                 ]
  3253.             };
  3254.         }
  3255.         else {
  3256.             var surveyJSON = {
  3257.                 showTitle: false,
  3258.                 completeText: 'Submit',
  3259.                 requiredText: '',
  3260.                 focusFirstQuestionAutomatic: false,
  3261.                 pages:
  3262.                 [
  3263.                     {
  3264.                         name:'page1',
  3265.                         questions:
  3266.                         [
  3267.                             {
  3268.                                 type: 'radiogroup',
  3269.                                 choices: <?=$choicesJSArray?>,
  3270.                                 isRequired: true,
  3271.                                 name: 'question',
  3272.                                 title: <?=json_encode($poll->getTitle())?>
  3273.                             }
  3274.                         ]
  3275.                     }
  3276.                 ]
  3277.             };
  3278.         }
  3279.             
  3280.             var survey = new Survey.Model(surveyJSON);
  3281.             
  3282.             $('#surveyContainer').Survey({
  3283.                 model:survey,
  3284.                 //allowComplete: false,
  3285.                 //onCompleting:sendDataToServer,
  3286.                 onComplete:sendDataToServer,
  3287.                 showQuestionNumbers: 'off',
  3288.                 completedHtml: '<div id="pollLoadingContainer"><div id="pollLoader"></div></div><div id="beforePoll"></div><canvas id="pollResults" width="400" height="300" style="display:none;"></canvas><div id="afterPoll"></div>'
  3289.             });
  3290.             
  3291.             if(<?=$allowSubmission?> == 0) {
  3292.                 survey.onCompleting.add((result, options) => {
  3293.                     options.allowComplete = false;
  3294.                     $("#surveyContainer").html("<?=$signInForm?>");
  3295.                 });
  3296.             }
  3297.             
  3298.             function sendDataToServer(survey) {
  3299.                 
  3300.                 //var resultAsString = JSON.stringify(survey.data);
  3301.                 //alert(resultAsString);
  3302.                 
  3303.                 var pollOptionId = survey.data.question;
  3304.                 
  3305.                 $.post("/ajax/pollResponse",
  3306.                 {
  3307.                     pollId: <?=$poll->getId()?>,
  3308.                     pollOptionId: pollOptionId,
  3309.                     userId: <?=$userId?>
  3310.                 },
  3311.                 function(data,status){
  3312.                     //survey.completedHtml = "Hooray!";
  3313.                     //survey.clear(true, true);
  3314.                     //survey.doComplete();
  3315.                     
  3316.                     renderPoll(data);
  3317.                     
  3318.                 });
  3319.                 
  3320.                 //document.cookie = 'poll=' + $(this).val() + ";path=/";
  3321.                 document.cookie = "poll" + <?=$poll->getId()?> + "=1;path=/";
  3322.                 //$pollCookie = $this->request->cookies->set("poll", "1");
  3323.             }
  3324.         </script>
  3325.         <?php
  3326.         $module .= ob_get_clean();
  3327.         
  3328.         return $module;
  3329.     }
  3330.     
  3331.     public function usd ($amount "")
  3332.     {
  3333.         $amount = (int) $amount;
  3334.         return "$" number_format(($amount 100), 2);
  3335.     }
  3336.     public function getUniqueRandomNumbers($min$max$quantity) {
  3337.         $numbers range($min$max);
  3338.         shuffle($numbers);
  3339.         return array_slice($numbers0$quantity);
  3340.     }
  3341.     public function tagShortcodes($pee) {
  3342.         preg_match_all("/(\[([\w]+)[^\]]*\])(.*?)(\[\/\\2\])/"$pee$matchesPREG_SET_ORDER);
  3343.         //$again = false;
  3344.         if (!empty($matches)) {
  3345.             /*
  3346.             Example:
  3347.             <a href=howdy.html>click me</a>
  3348.             $val[0]    <a href=howdy.html>click me</a>
  3349.             $val[1]    <a href=howdy.html>
  3350.             $val[2]    a
  3351.             $val[3]    click me
  3352.             $val[4]    </a>
  3353.             */
  3354.             foreach ($matches as $val) {
  3355.                 $type $val[2];
  3356.                 switch ($type) {
  3357.                     case "img":
  3358.                         $pee str_replace(
  3359.                             $val[0],
  3360.                             "<img src='$val[3]' loading='lazy' />",
  3361.                             $pee
  3362.                         );
  3363.                         break;
  3364.                     case "url":
  3365.                         if($val[1] == "[url]") {
  3366.                             $href $val[3];
  3367.                         }
  3368.                         else {
  3369.                             $href substr(substr($val[1], 0, -1), strpos($val[1], "=") + 1);
  3370.                         }
  3371.                         $pee str_replace(
  3372.                             $val[0],
  3373.                             "<a href='$href' target='_blank'>".$val[3]."</a>",
  3374.                             $pee
  3375.                         );
  3376.                         break;
  3377.                 }
  3378.                 /*
  3379.                 if(!$again) {
  3380.                     preg_match_all("/(\[([\w]+)[^\]]*\])(.*?)(\[\/\\2\])/", $val[3], $matches2, PREG_SET_ORDER);
  3381.                     if (!empty($matches2)) {
  3382.                         $again = true;
  3383.                     }
  3384.                 }
  3385.                 */
  3386.             }
  3387.             /*
  3388.             if($again) {
  3389.                 $pee = $this->tagShortcodes($pee);
  3390.             }
  3391.             */
  3392.             //$pee = $this->tagShortcodes($pee);
  3393.         }
  3394.         return $pee;
  3395.     }
  3396. }