Example #1
0
 /**
  * Display repeater view
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $repeaterId = $content;
     $template = !empty($options['view']) ? $options['view'] : $this->_block->name;
     $repeatersViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.repeaters.';
     if (!empty($options['form'])) {
         return FormWrap::view($this->_block, $options, $repeatersViews . $template . '-form');
     }
     if (View::exists($repeatersViews . $template)) {
         $renderedContent = '';
         if ($repeaterBlocks = BlockRepeater::getRepeaterBlocks($this->_block->id)) {
             $random = !empty($options['random']) ? $options['random'] : false;
             $repeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId, $options['version'], $random);
             // pagination
             if (!empty($options['per_page']) && !empty($repeaterRows)) {
                 $pagination = new LengthAwarePaginator($repeaterRows, count($repeaterRows), $options['per_page'], Request::input('page', 1));
                 $pagination->setPath(Request::getPathInfo());
                 $paginationLinks = PaginatorRender::run($pagination);
                 $repeaterRows = array_slice($repeaterRows, ($pagination->currentPage() - 1) * $options['per_page'], $options['per_page'], true);
             } else {
                 $paginationLinks = '';
             }
             if (!empty($repeaterRows)) {
                 $i = 1;
                 $isFirst = true;
                 $isLast = false;
                 $rows = count($repeaterRows);
                 $cols = !empty($options['cols']) ? (int) $options['cols'] : 1;
                 $column = !empty($options['column']) ? (int) $options['column'] : 1;
                 foreach ($repeaterRows as $rowId => $row) {
                     if ($i % $cols == $column % $cols) {
                         $previousKey = PageBuilder::getCustomBlockDataKey();
                         PageBuilder::setCustomBlockDataKey('repeater' . $repeaterId . '.' . $rowId);
                         foreach ($repeaterBlocks as $repeaterBlock) {
                             if ($repeaterBlock->exists) {
                                 PageBuilder::setCustomBlockData($repeaterBlock->name, !empty($row[$repeaterBlock->id]) ? $row[$repeaterBlock->id] : '', null, false);
                             }
                         }
                         if ($i + $cols - 1 >= $rows) {
                             $isLast = true;
                         }
                         $renderedContent .= View::make($repeatersViews . $template, array('is_first' => $isFirst, 'is_last' => $isLast, 'count' => $i, 'total' => $rows, 'id' => $repeaterId, 'pagination' => $paginationLinks, 'links' => $paginationLinks))->render();
                         $isFirst = false;
                         PageBuilder::setCustomBlockDataKey($previousKey);
                     }
                     $i++;
                 }
             }
         }
         return $renderedContent;
     } else {
         return "Repeater view does not exist in theme";
     }
 }
Example #2
0
 /**
  * Display video using info from youtube API
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     if (!empty($content)) {
         $template = !empty($options['view']) ? $options['view'] : 'default';
         $videoViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.videos.';
         if (!View::exists($videoViews . $template)) {
             return 'Video template not found';
         }
         if (!($videoInfo = $this->_cache($content))) {
             return 'Video does not exist, it may have been removed from youtube';
         }
         return View::make($videoViews . $template, ['video' => $videoInfo])->render();
     } else {
         return '';
     }
 }
Example #3
0
 /**
  * Frontend display for the block
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     if (!empty($options['meta']) || !empty($options['pageBuilder'])) {
         $content = preg_replace_callback('/{{\\s*\\$(?P<block>\\w*)\\s*}}/', function ($matches) {
             return str_replace('"', "'", strip_tags(PageBuilder::block($matches['block'])));
         }, $content);
         $content = str_replace('%page_name%', PageBuilder::pageName(), $content);
         $content = str_replace('%site_name%', config('coaster::site.name'), $content);
     }
     if (!empty($options['meta'])) {
         $content = trim(str_replace(PHP_EOL, ' ', $content));
         $content = preg_replace('/\\s+/', ' ', $content);
         $content = htmlentities(strip_tags(html_entity_decode($content, ENT_QUOTES, 'UTF-8')));
         $content = StringHelper::cutString($content);
     }
     return $content;
 }
Example #4
0
 /**
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     if ($galleryData = $this->_defaultData($content)) {
         uasort($galleryData, [GalleryUploadHandler::class, 'order_items']);
         foreach ($galleryData as $image => $imageData) {
             $galleryData[$image]->file = '/uploads/system/gallery/' . $this->_block->name . $imageData->path . $image;
         }
     }
     $options['view'] = !empty($options['view']) ? $options['view'] : 'default';
     $galleryViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.gallery.';
     if (empty($options['view']) && View::exists($galleryViews . $this->_block->name)) {
         return View::make($galleryViews . $this->_block->name, ['images' => $galleryData])->render();
     } elseif (View::exists($galleryViews . $options['view'])) {
         return View::make($galleryViews . $options['view'], ['images' => $galleryData])->render();
     } else {
         return 'Gallery template not found';
     }
 }
Example #5
0
 /**
  * Display image, image can be cropped with croppa
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $imageData = $this->_defaultData($content);
     if (empty($imageData->file)) {
         return '';
     }
     if (empty($imageData->title)) {
         if (empty($options['title'])) {
             $fileName = substr(strrchr($imageData->file, '/'), 1);
             $imageData->title = str_replace('_', ' ', preg_replace('/\\.[^.\\s]{3,4}$/', '', $fileName));
         } else {
             $imageData->title = $options['title'];
         }
     }
     $imageData->extra_attrs = '';
     $ignoreAttributes = ['height', 'width', 'group', 'view', 'title', 'croppaOptions', 'version'];
     foreach ($options as $option => $val) {
         if (!in_array($option, $ignoreAttributes)) {
             $imageData->extra_attrs .= $option . '="' . $val . '" ';
         }
     }
     $imageData->group = !empty($options['group']) ? $options['group'] : '';
     $imageData->original = URL::to($imageData->file);
     $height = !empty($options['height']) ? $options['height'] : null;
     $width = !empty($options['width']) ? $options['width'] : null;
     if ($height || $width) {
         $croppaOptions = !empty($options['croppaOptions']) ? $options['croppaOptions'] : [];
         $imageData->file = str_replace(URL::to('/'), '', $imageData->file);
         $imageData->file = \Croppa::url($imageData->file, $width, $height, $croppaOptions);
     } else {
         $imageData->file = $imageData->original;
     }
     $template = !empty($options['view']) ? $options['view'] : 'default';
     $imageViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.images.';
     if (View::exists($imageViews . $template)) {
         return View::make($imageViews . $template, array('image' => $imageData))->render();
     } else {
         return 'Image template not found';
     }
 }
 /**
  * Display pages selected with view
  * Also reverse lookup option, find pages with the current page selected
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $pages = [];
     $page_ids = [];
     if (isset($options['reverse'])) {
         // get page_ids on which current page is selected in this block
         $currentPageId = PageBuilder::pageId(true);
         if ($currentPageId) {
             $same_blocks = PageBlock::where('block_id', '=', $this->_block->id)->get();
             foreach ($same_blocks as $same_block) {
                 $block_page_ids = @unserialize($same_block->content);
                 if (!empty($block_page_ids)) {
                     foreach ($block_page_ids as $k => $block_page_id) {
                         $block_page_id = Path::unParsePageId($block_page_id);
                         if ($currentPageId == $block_page_id) {
                             $page_ids[] = $same_block->page_id;
                             break;
                         }
                     }
                 }
             }
         }
     } elseif (!empty($content)) {
         $page_ids = unserialize($content);
     }
     if (!empty($page_ids)) {
         foreach ($page_ids as $page_id) {
             $parsedPageId = Path::unParsePageId($page_id, false);
             $pages[$page_id] = new PageDetails($parsedPageId[0], !empty($parsedPageId[1]) ? $parsedPageId[1] : 0);
         }
     }
     $template = !empty($options['view']) ? $options['view'] : $this->_block->name;
     $selectPageViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.selectpages.';
     if (View::exists($selectPageViews . $template)) {
         return View::make($selectPageViews . $template, array('pages' => $pages))->render();
     } else {
         return 'Select pages template not found';
     }
 }
Example #7
0
 /**
  * Save form data and send email
  * @param array $formData
  * @return bool|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function submission($formData)
 {
     if ($form_settings = $this->_block->getContent(true)) {
         $form_settings = $this->_defaultData($form_settings);
         $form_rules = BlockFormRule::get_rules($form_settings->template);
         $v = Validator::make($formData, $form_rules);
         $captcha = Securimage::captchaCheck();
         // check form rules
         if ($v->passes() && !($form_settings->captcha == true && !$captcha)) {
             // delete blank and system fields
             unset($formData['captcha_code']);
             // Save data function (override this function to save data differently)
             $form_submission = $this->submissionSaveData($formData);
             if (!$form_submission->id) {
                 FormMessage::add('submission_save_error', 'Unable to save the form.');
             }
             // Send email
             if ($this->submissionSendEmail($formData, $form_settings)) {
                 $form_submission->sent = 1;
                 $form_submission->save();
             }
             Session::set('form_data', $form_submission);
             return \redirect(PageBuilder::pageUrl($form_settings->page_to));
         } else {
             FormMessage::set($v->messages());
             if (!$captcha) {
                 FormMessage::add('captcha_code', 'Invalid Captcha Code, try again.');
             }
         }
     }
     return false;
 }
 /**
  * @param string $viewPath
  * @param array $data
  * @return string
  */
 protected static function _getRenderedView($viewPath, $data = [])
 {
     $viewPath = 'themes.' . PageBuilder::getData('theme') . '.menus.' . self::$_view . '.' . $viewPath;
     if (View::exists($viewPath)) {
         return View::make($viewPath, $data)->render();
     } else {
         return 'View not found (' . $viewPath . ')';
     }
 }
Example #9
0
 public static function sendFromFormData($templates, $formData, $subject, $to = null, $from = null)
 {
     // get email details to send to
     $emailDetails = ['subject' => $subject, 'to' => $to ?: config('coaster::site.email'), 'from' => $from ?: config('coaster::site.email'), 'userEmail' => null];
     // split to addresses
     if (strpos($emailDetails['to'], ',') !== false) {
         $emailDetails['to'] = explode(',', $emailDetails['to']);
     }
     $emailCheck = Validator::make($emailDetails, ['from' => 'email|required']);
     $emailCheck->each('to.*', 'required|email');
     if ($emailCheck->passes()) {
         // get templates
         $emailsViews = ['themes.' . PageBuilder::getData('theme') . '.emails.'];
         foreach ($templates as $template) {
             $emailsViews[] = $emailsViews[0] . $template . '.';
         }
         $sendTemplate = null;
         $replyTemplate = null;
         foreach ($emailsViews as $emailsView) {
             if (!$sendTemplate && View::exists($emailsView . 'default')) {
                 $sendTemplate = $emailsView . 'default';
             }
             if (!$replyTemplate && View::exists($emailsView . 'reply')) {
                 $replyTemplate = $emailsView . 'reply';
             }
         }
         if (!$sendTemplate) {
             throw new CmsPageException('No default email template', 500);
         }
         $replyTemplate = $replyTemplate ?: $sendTemplate;
         // generate body
         $body = '';
         foreach ($formData as $field => $value) {
             if (is_array($value)) {
                 $value = implode(", ", $value);
             }
             if (strpos($value, "\r\n") !== false) {
                 $value = "<br />" . str_replace("\r\n", "<br />", $value);
             }
             $body .= ucwords(str_replace('_', ' ', $field)) . ": {$value} <br />";
             if (stristr($field, 'email') !== false) {
                 $emailDetails['userEmail'] = $value;
             }
         }
         Mail::send($sendTemplate, ['body' => $body, 'formData' => $formData, 'form_data' => $formData], function (Message $message) use($emailDetails) {
             if ($emailDetails['userEmail']) {
                 $message->replyTo($emailDetails['userEmail']);
             }
             $message->to($emailDetails['to']);
             $message->from($emailDetails['from']);
             $message->subject($emailDetails['subject']);
         });
         if ($emailDetails['userEmail']) {
             Mail::send($replyTemplate, ['body' => $body, 'formData' => $formData, 'form_data' => $formData], function (Message $message) use($emailDetails) {
                 $message->to($emailDetails['userEmail']);
                 $message->from($emailDetails['from']);
                 $message->subject($emailDetails['subject']);
             });
         }
         return !Mail::failures();
     } else {
         return false;
     }
 }
 /**
  * @param Exception $e
  */
 protected function _setErrorContent(Exception $e)
 {
     $this->responseCode = !empty(\Symfony\Component\HttpFoundation\Response::$statusTexts[$e->getCode()]) ? $e->getCode() : 500;
     $templatePath = PageBuilder::themePath() . 'errors.' . $this->responseCode;
     // display error loading page
     event(new LoadErrorTemplate($templatePath));
     if (View::exists($templatePath)) {
         $this->_setHtmlContentType();
         $this->responseContent = View::make($templatePath, ['e' => $e, 'error' => $e->getMessage()])->render();
     } else {
         $this->responseContent = $e->getMessage();
     }
 }
 private static function _processFileBlocks()
 {
     self::$_fileBlocks = [];
     self::$_fileGlobalBlocks = [];
     $blockCounter = [];
     $templateCount = 0;
     foreach (self::$_fileTemplateBlocks as $template => $blocks) {
         if (strpos($template, '__core_') !== 0) {
             $templateCount++;
         } else {
             // move non template specific blocks (repeater blocks) to end of array
             unset(self::$_fileTemplateBlocks[$template]);
             self::$_fileTemplateBlocks[$template] = $blocks;
         }
     }
     $blockOrders = [];
     foreach (self::$_allBlocks as $block => $details) {
         $blockOrders[$block] = $details->order;
     }
     // force template adds from overwrite file
     if (!empty(self::$_blockSettings)) {
         foreach (self::$_blockSettings as $block => $fields) {
             if (!empty($fields['templates'])) {
                 if ($fields['templates'] == '*') {
                     foreach (self::$_fileTemplateBlocks as $template => $blocks) {
                         if (!in_array($block, self::$_fileTemplateBlocks[$template]) && strpos($template, '__core_') !== 0) {
                             self::$_fileTemplateBlocks[$template][] = $block;
                             PageBuilder::setData('template', $template);
                             PageBuilder::block($block);
                         }
                     }
                 } else {
                     $templates = explode(',', $fields['templates']);
                     if (!empty($templates)) {
                         foreach ($templates as $template) {
                             if (isset(self::$_fileTemplateBlocks[$template])) {
                                 if (!in_array($block, self::$_fileTemplateBlocks[$template])) {
                                     self::$_fileTemplateBlocks[$template][] = $block;
                                     PageBuilder::setData('template', $template);
                                     PageBuilder::block($block);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // create fileBlockTemplates array
     self::$_fileBlockTemplates = [];
     self::$_fileCoreBlockTemplates = [];
     foreach (self::$_fileTemplateBlocks as $template => $blocks) {
         if (strpos($template, '__core_') !== 0) {
             foreach ($blocks as $block) {
                 if (!isset(self::$_fileBlockTemplates[$block])) {
                     self::$_fileBlockTemplates[$block] = [];
                 }
                 self::$_fileBlockTemplates[$block][] = $template;
             }
         }
         foreach ($blocks as $block) {
             if (!isset(self::$_fileCoreBlockTemplates[$block])) {
                 self::$_fileCoreBlockTemplates[$block] = [];
             }
             self::$_fileCoreBlockTemplates[$block][] = $template;
         }
     }
     // get full block list and details in one array
     foreach (self::$_fileTemplateBlocks as $template => $blocks) {
         $order = 10;
         foreach ($blocks as $k => $block) {
             if (!isset(self::$_fileBlocks[$block])) {
                 if (!empty(self::$_blockSettings[$block]['order'])) {
                     $blockOrders[$block] = self::$_blockSettings[$block]['order'];
                 } else {
                     if (isset($blocks[$k - 1]) && !empty($blockOrders[$blocks[$k - 1]])) {
                         $order = $blockOrders[$blocks[$k - 1]] + 10;
                     } else {
                         $order += 10;
                     }
                     $blockOrders[$block] = $order;
                 }
                 $blockCounter[$block] = 0;
                 self::$_fileBlocks[$block] = ['order' => $blockOrders[$block]];
                 self::$_fileBlocks[$block] = ['order' => $blockOrders[$block]];
                 if (in_array($block, self::$_repeaterBlocks)) {
                     self::$_fileBlocks[$block]['type'] = 'repeater';
                 }
             }
             if (strpos($template, '__core_') !== 0) {
                 $blockCounter[$block]++;
             }
         }
     }
     foreach ($blockCounter as $block => $count) {
         if ($count / $templateCount >= 0.7) {
             self::$_fileGlobalBlocks[$block] = 1;
         }
     }
 }