public static function updateAllSearchData()
 {
     self::truncate();
     $pageLanguages = PageLang::all();
     foreach ($pageLanguages as $pageLang) {
         static::updateText(strip_tags($pageLang->name), 0, $pageLang->page_id, $pageLang->language_id);
         $pageBlocks = Block::getDataForVersion(new PageBlock(), $pageLang->live_version, ['language_id' => $pageLang->language_id, 'page_id' => $pageLang->page_id]);
         foreach ($pageBlocks as $pageBlock) {
             $block = Block::preloadClone($pageBlock->block_id)->setPageId($pageBlock->page_id);
             $searchText = $block->search_weight > 0 ? $block->getTypeObject()->generateSearchText($pageBlock->content) : '';
             static::updateText($searchText, $pageBlock->block_id, $pageBlock->page_id, $pageBlock->language_id);
         }
     }
 }
 /**
  * @param string $block_name
  * @param array $options
  * @return mixed|string
  */
 public function block($block_name, $options = [])
 {
     if ($this->_importIgnore($options)) {
         return '';
     }
     if (empty($options['version'])) {
         $options['version'] = 0;
     }
     $block_name = strtolower($block_name);
     // get block type
     if (isset($this->blockSettings[$block_name]['type'])) {
         $block = new Block();
         $block->type = $this->blockSettings[$block_name]['type'];
     } else {
         $block = Block::preloadClone($block_name);
     }
     if (!$block->type) {
         $block->type = BlockUpdater::typeGuess($block_name);
     }
     // check if repeater view
     if (!empty($options['view'])) {
         $repeaterView = $options['view'];
     } else {
         $repeaterView = $block_name;
     }
     if ($block->type == 'repeater' || in_array($repeaterView, $this->repeaterTemplates)) {
         $tmp = $this->repeaterView;
         $this->repeaterView = $block_name;
         // manually call the repeater view as the Repeater::display function won't work if RepeaterBlock table returns no results
         $output = View::make('themes.' . $this->theme . '.blocks.repeaters.' . $repeaterView, ['is_first' => true, 'is_last' => true, 'count' => 1, 'total' => 1, 'id' => 1, 'pagination' => ''])->render();
         $this->repeaterView = $tmp;
     } else {
         // always use blank data for processing blocks
         $output = $block->getTypeObject()->display('', $options);
     }
     if ($this->repeaterView) {
         // if in a repeater template
         if (!isset($this->repeaterBlocks[$this->repeaterView])) {
             $this->repeaterBlocks[$this->repeaterView] = [];
         }
         if (!in_array($block_name, $this->repeaterBlocks[$this->repeaterView])) {
             $this->repeaterBlocks[$this->repeaterView][] = $block_name;
         }
         $template = '__core_repeater';
     } elseif ($this->categoryView) {
         $template = '__core_category';
     } else {
         // if in a normal template
         if (!array_key_exists('page_id', $options)) {
             $template = $this->template;
         } else {
             $template = '__core_otherPage';
         }
     }
     if (!isset($this->templateBlocks[$template])) {
         $this->templateBlocks[$template] = [];
     }
     if (!in_array($block_name, $this->templateBlocks[$template])) {
         $this->templateBlocks[$template][] = $block_name;
     }
     if (!empty($options['importNote'])) {
         if (!isset($this->blockSettings[$block_name])) {
             $this->blockSettings[$block_name] = [];
         }
         if (!isset($this->blockSettings[$block_name]['note'])) {
             $this->blockSettings[$block_name]['note'] = $options['importNote'];
         }
     }
     foreach (['importReturnValue', 'import_return_value'] as $returnValueKey) {
         if (!empty($options[$returnValueKey])) {
             $output = $options[$returnValueKey];
         }
     }
     return $output;
 }
示例#3
0
 public function getComments($data, $page)
 {
     $commentData = collect($this->getJson($this->url . '/wp-json/wp/v2/comments/?post=' . $data->id));
     $idsInserted = [];
     foreach ($commentData as $comment) {
         $check = PageBlockRepeaterData::where('content', '=', $comment->content->rendered)->first();
         if (!$check) {
             $rowData['comment_author'] = $comment->author_name;
             $rowData['comment_url'] = $comment->author_url;
             $rowData['comment_message'] = $comment->content->rendered;
             $rowData['comment_status'] = $comment->status;
             $rowData['comment_parent'] = isset($idsInserted[$comment->parent]) ? $idsInserted[$comment->parent] : 0;
             $rowData['comment_date'] = $this->carbonDate($comment->date)->format('Y-m-d H:i:s');
             $rowInfo = Block::preloadClone('comments')->setPageId($page->id)->getTypeObject()->insertRow($rowData);
             $idsInserted[$comment->id] = $rowInfo->row_id;
         } else {
             $idsInserted[$comment->id] = $check->row_id;
         }
     }
 }
示例#4
0
 /**
  * Add new repeater row with passed block contents onto end of repeater rows (or create repeater and set as first row)
  * @param array $repeaterBlockContents
  */
 public function insertRow($repeaterBlockContents)
 {
     if (!($repeaterId = $this->_block->getContent())) {
         $repeaterId = PageBlockRepeaterRows::nextFreeRepeaterId();
         $this->save($repeaterId);
         $currentRepeaterRows = [];
     } else {
         $currentRepeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId);
     }
     $repeaterRowId = PageBlockRepeaterRows::nextFreeRepeaterRowId($repeaterId);
     if (!array_key_exists(0, $repeaterBlockContents)) {
         if (!empty($currentRepeaterRows)) {
             $rowOrders = array_map(function ($row) {
                 return !empty($row[0]) ? $row[0] : 0;
             }, $currentRepeaterRows);
             $repeaterBlockContents[0] = max($rowOrders) + 1;
         } else {
             $repeaterBlockContents[0] = 1;
         }
     }
     foreach ($repeaterBlockContents as $blockName => $content) {
         $block = Block::preloadClone($blockName);
         if ($block->exists || $blockName == 0) {
             $block->id = $blockName === 0 ? 0 : $block->id;
             $block->setVersionId($this->_block->getVersionId())->setRepeaterData($repeaterId, $repeaterRowId)->setPageId($this->_block->getPageId())->getTypeObject()->save($content);
         }
     }
 }
 /**
  * @param string $blockName
  * @param array $options
  * @return mixed|string
  */
 public function block($blockName, $options = [])
 {
     // force query available if block details changed in current request
     $block = Block::preloadClone($blockName, isset($options['force_query']));
     $pageId = !empty($options['page_id']) ? Path::unParsePageId($options['page_id']) : $this->pageId();
     $usingGlobalContent = false;
     $blockData = null;
     if (($customBlockData = $this->_getCustomBlockData($blockName)) !== null) {
         // load custom block data for (is also used for repeater content)
         $blockData = $customBlockData;
     } elseif ($block->exists) {
         // load block data
         $globalBlockData = PageBlockDefault::preload($block->id);
         $pageBlockData = PageBlock::preloadPageBlock($pageId, $block->id, $this->pageVersion($pageId));
         // get languages
         $loadForLanguages = [Language::current()];
         if (config('coaster::frontend.language_fallback') == 1 && !in_array(config('coaster::frontend.language'), $loadForLanguages)) {
             $loadForLanguages[] = config('coaster::frontend.language');
         }
         // run through languages until block data found
         foreach ($loadForLanguages as $language) {
             if (!empty($pageBlockData[$language])) {
                 // if custom page block for selected language exists
                 $blockData = $pageBlockData[$language]->content;
             } elseif (!empty($globalBlockData[$language])) {
                 // if default block for selected language exists
                 $blockData = $globalBlockData[$language]->content;
                 $usingGlobalContent = true;
                 break;
             }
         }
         // return raw data
         if (isset($options['raw']) && $options['raw']) {
             return $blockData;
         }
     } else {
         return 'block not found';
     }
     // set version that data has been grabbed for (0 = latest)
     if (empty($options['version'])) {
         $options['version'] = $usingGlobalContent ? 0 : $this->pageVersion($pageId);
     }
     // pass block details and data to display class
     return $block->setPageId($pageId)->setVersionId($options['version'])->getTypeObject()->display($blockData, $options);
 }