Exemple #1
0
 /**
  * Convert new lines to <br /> by default, also added length option which cuts string to a word nicely
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $content = parent::display($content, $options);
     if (!empty($options['source'])) {
         return $content;
     }
     if (isset($options['meta']) && !isset($options['nl2br'])) {
         $options['nl2br'] = $options['meta'];
     }
     if (isset($options['nl2br']) && $options['nl2br'] || !isset($options['nl2br'])) {
         $content = nl2br($content);
     }
     if (!empty($options['length'])) {
         $content = StringHelper::cutString(strip_tags($content), $options['length']);
     }
     return $content;
 }
 /**
  * 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;
 }
 public function getPages($groupId)
 {
     $group = PageGroup::preload($groupId);
     if ($group->exists) {
         $pageIds = $group->itemPageIds(false, true);
         $attributes = PageGroupAttribute::where('group_id', '=', $groupId)->get();
         $attributeBlocks = [];
         foreach ($attributes as $attribute) {
             $block = Block::preload($attribute->item_block_id);
             if ($block->exists) {
                 $attributeBlocks[$attribute->item_block_id] = $block;
             }
         }
         $pageRows = '';
         if (!empty($pageIds)) {
             foreach ($pageIds as $pageId) {
                 $pageLang = PageLang::preload($pageId);
                 $showBlocks = [];
                 $canEdit = Auth::action('pages.edit', ['page_id' => $pageId]);
                 $canDelete = Auth::action('pages.delete', ['page_id' => $pageId]);
                 foreach ($attributeBlocks as $attributeBlock) {
                     $pageBlockContent = PageBlock::preloadPageBlockLanguage($pageId, $attributeBlock->id, -1, 'block_id')->content;
                     if (strpos($attributeBlock->type, 'selectmultiple') === 0 && !empty($pageBlockContent)) {
                         // selectmultiple
                         $showBlocks[] = implode(', ', unserialize($pageBlockContent));
                     } elseif ($attributeBlock->type == 'datetime' && !empty($pageBlockContent)) {
                         // datetime
                         $showBlocks[] = (new Carbon($pageBlockContent))->format(config('coaster::date.format.long'));
                     } else {
                         // text/string/select
                         $showBlocks[] = strip_tags(StringHelper::cutString($pageBlockContent, 50));
                     }
                 }
                 $pageRows .= View::make('coaster::partials.groups.page_row', array('page_lang' => $pageLang, 'item_name' => $group->item_name, 'showBlocks' => $showBlocks, 'can_edit' => $canEdit, 'can_delete' => $canDelete))->render();
             }
         }
         $pagesTable = View::make('coaster::partials.groups.page_table', array('rows' => $pageRows, 'item_name' => $group->item_name, 'blocks' => $attributeBlocks))->render();
         $this->layoutData['modals'] = View::make('coaster::modals.general.delete_item');
         $this->layoutData['content'] = View::make('coaster::pages.groups', array('group' => $group, 'pages' => $pagesTable, 'can_add' => $group->canAddItems(), 'can_edit' => $group->canEditItems()));
     }
 }