public function handle()
{
- $index = env('ELASTICSEARCH_INDEX_NAME', 'cubist_elastic_default_1');
- echo env('ELASTICSEARCH_HOST');
+ $index = config('cubist.internal_search_index');
try {
Elasticsearch::indices()->delete(['index' => $index]);
} catch (\Exception $e) {
echo $e->getMessage();
}
+
Elasticsearch::indices()->create(
[
'index' => $index,
$doc = new DOMSelector($html);
/** @var \DOMElement $meta */
- $meta = $doc->select('meta[data-search]')[0];
+ $meta = $doc->select('meta[data-search]', false)[0];
$enabled = $meta->getAttribute('data-search') == '1';
if (!$enabled) {
continue;
$keywords = $meta->getAttribute('data-keywords');
$body = [
- 'long_title' => (string)$doc->select('title')[0],
'short_title' => $short_title,
+ 'long_title' => (string)$doc->select('title')[0]['text'],
'keywords' => $keywords,
- 'main' => $doc->getDOM()->saveHTML($doc->select('main')->item(0)),
+ 'description' => $doc->select('meta[name="description"]')[0]['attributes']['content'],
+ 'main' => $doc->getDOM()->saveHTML($doc->select('main', false)->item(0)),
];
$data = [
'label' => 'Activer',
'default' => true,
'hint' => 'Référencer cette page dans le moteur de recherche interne',
- 'tab' => $tab]);
+ 'tab' => $tab,
+ 'fake' => true,
+ 'store_in' => 'search_internal']);
$this->addField(['name' => 'search_internal_keywords',
'type' => 'Tags',
'label' => 'Mots clés',
'hint' => 'Mots supplémentaires à utiliser par le moteur de recherche',
- 'tab' => $tab]);
+ 'tab' => $tab,
+ 'translatable' => true,
+ 'fake' => true,
+ 'store_in' => 'search_internal']);
}
protected function _seo()
'type' => 'Text',
'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
'tab' => $tab,
+ 'fake' => true,
'store_in' => 'seo',
]);
'type' => 'Textarea',
'hint' => __('Recommended length: 160 chars'),
'tab' => $tab,
+ 'fake' => true,
'store_in' => 'seo',
]);
'type' => 'Checkbox',
'default' => true,
'tab' => $tab,
+ 'fake' => true,
'store_in' => 'seo',
]);
}
public function setFields()
{
- parent::setFields();
-
$this->addField(['name' => 'title',
'label' => 'Titre',
'type' => 'Text',
'column' => true,
- 'elastic' => true,]);
-
- $this->addField(['name' => 'slug',
- 'type' => 'Slug',
- 'label' => 'Slug (URL)']);
+ 'tab'=>'Contenus']);
$this->addField(['name' => 'type',
'type' => 'SelectFromArray',
'label' => 'Type',
'options' => ['news' => 'Actualité', 'event' => 'Evénement'],
'column' => true,
+ 'tab'=>'Contenus'
]);
$this->addField(['name' => 'date',
'type' => 'Datetime',
'label' => 'Date de publication',
- 'column' => true]);
+ 'column' => true,
+ 'tab'=>'Contenus']);
$this->addField(['name' => 'event_start',
'type' => 'Date',
'label' => 'Début de l\'évenement',
'when' => ['type' => ['event']],
+ 'tab'=>'Contenus'
]);
$this->addField(['name' => 'event_end',
'type' => 'Text',
'label' => 'Lieu de l\'événement',
'when' => ['type' => ['event']],
- 'elastic' => true,
+ 'tab'=>'Contenus'
]);
$this->addField(['name' => 'chapo',
'label' => 'Chapo',
'hint' => 'Texte court affiché sur le listing des actualités',
'when' => ['type' => ['news']],
- 'elastic' => true,
+ 'tab'=>'Contenus'
]);
$this->addField(['name' => 'image',
'type' => 'Images',
- 'label' => 'Image']);
+ 'label' => 'Image',
+ 'tab'=>'Contenus']);
$this->addField(['name' => 'content',
'type' => 'Markdown',
'label' => 'Contenu',
- 'elastic' => true,
+ 'tab'=>'Contenus'
]);
$this->addField(['name' => 'status',
'type' => 'SelectFromArray',
'label' => 'Status',
'options' => ['0' => 'Offline', '1' => 'Published'],
- 'column' => true
+ 'column' => true,
+ 'tab'=>'Contenus'
]);
+
+ parent::setFields();
}
}
}
/**
- * @param string $offset
+ * @param string|array $offset
* @param mixed $default
* @return mixed
*/
public function get($offset, $default = null)
{
- $res = Arr::get($this->_data, $offset, $default);
-
- // If an array value is saved without any items, it might be returned
- // as a string "[]" when instead it should be an empty array...
- if ($res === '[]') {
- $res = [];
+ if (!is_array($offset)) {
+ $offset = [$offset];
}
- // Get the translated value if the array contains a key matching the locale.
- // We have to check if the key exists because the actual value may be null.
- // Using isset() on the locale key would give a false negative if the value is null.
- if (is_array($res) && array_key_exists(App::getLocale(), $res)) {
- $res = $res[App::getLocale()];
- }
+ foreach ($offset as $key) {
+ if (!Arr::has($this->_data, $key)) {
+ continue;
+ }
- if (!$res) {
- return $default;
- }
+ $res = Arr::get($this->_data, $key, $default);
- return $res;
+ // If an array value is saved without any items, it might be returned
+ // as a string "[]" when instead it should be an empty array...
+ if ($res === '[]') {
+ $res = [];
+ }
+
+ // Get the translated value if the array contains a key matching the locale.
+ // We have to check if the key exists because the actual value may be null.
+ // Using isset() on the locale key would give a false negative if the value is null.
+ if (is_array($res) && array_key_exists(App::getLocale(), $res)) {
+ $res = $res[App::getLocale()];
+ }
+
+ if (!$res) {
+ return $default;
+ }
+ return $res;
+
+ }
+ return $default;
}
/**
<?php
return [
'internal_search' => env('CUBIST_INTERNAL_SEARCH', false),
+ 'internal_search_index' => env('CUBIST_INTERNAL_SEARCH_INDEX', strtolower(env('APP_NAME', 'App_name') . '_' . env('APP_ENV', 'dev'))),
'page_model' => '\App\Models\Page',
'settings_model' => '\App\Models\Settings',
];