/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('search_texts', function (Blueprint $table) {
         $table->increments('id');
         $table->integer('page_vid')->unsigned()->nullable()->references('id')->on('page_versions')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->integer('page_id')->unsigned()->references('id')->on('pages')->onUpdate('CASCADE')->onDelete('CASCADE');
         $table->integer('embargoed_until')->unsigned()->nullable();
         $table->string('title', 75)->nullable();
         $table->string('standfirst', '255')->null();
         $table->longText('text')->nullable();
     });
     DB::statement('ALTER TABLE search_texts ENGINE = "MyISAM"');
     DB::statement('CREATE FULLTEXT INDEX search_texts_title on search_texts(title)');
     DB::statement('CREATE FULLTEXT INDEX search_texts_standfirst on search_texts(standfirst)');
     DB::statement('CREATE FULLTEXT INDEX search_texts_text on search_texts(text)');
     DB::statement('CREATE FULLTEXT INDEX search_texts_all on search_texts(title, standfirst, text)');
     DB::statement('ALTER TABLE chunk_texts drop index text_fulltext');
     DB::statement('ALTER TABLE page_versions drop index title_fulltext');
     $finder = new Finder\Finder();
     $finder->addFilter(new Finder\VisibleInSiteSearch());
     $pages = $finder->findAll();
     foreach ($pages as $p) {
         DB::table('search_texts')->insert(['page_id' => $p->getId(), 'embargoed_until' => $p->getCurrentVersion()->getEmbargoedUntil()->getTimestamp(), 'page_vid' => $p->getCurrentVersion()->getId(), 'title' => $p->getTitle(), 'standfirst' => Chunk::get('text', 'standfirst', $p)->text(), 'text' => strip_tags(Chunk::get('text', 'bodycopy', $p)->text())]);
     }
 }
Ejemplo n.º 2
0
 public function handle(ChunkWasCreated $event)
 {
     $chunk = $event->getChunk();
     $type = $chunk->getType();
     $slotname = $chunk->getSlotname();
     $version = $event->getVersion();
     Chunk::saveToCache($type, $slotname, $version, $chunk);
 }
Ejemplo n.º 3
0
 public function handle(PageSearchSettingsWereUpdated $event)
 {
     $page = $event->getPage();
     $version = $page->getCurrentVersion();
     $standfirst = Chunk::find('text', 'standfirst', $version);
     $description = $page->getDescription();
     $description = $description == $standfirst ? '' : $description;
     SearchText::where('page_vid', '=', $version->getId())->update(['meta' => $page->getKeywords() . ' ' . $description]);
 }
Ejemplo n.º 4
0
 public function handle(PageVersionEvent $event)
 {
     $page = $event->getPage();
     $version = $event->getVersion();
     $standfirst = Chunk::find('text', 'standfirst', $version);
     $bodycopy = Chunk::find('text', 'bodycopy', $version);
     $description = $page->getDescription();
     $description = $description == $standfirst ? '' : $description;
     SearchText::create(['page_id' => $page->getId(), 'page_vid' => $version->getId(), 'embargoed_until' => $version->getEmbargoedUntil()->getTimestamp(), 'title' => $version->getTitle(), 'standfirst' => $standfirst ? $standfirst->text : '', 'text' => $bodycopy ? strip_tags($bodycopy->text) : '', 'meta' => $page->getKeywords() . ' ' . $description]);
 }
Ejemplo n.º 5
0
 /**
  * Get the text for the link.
  *
  * If text has been given then that is used.
  *
  * Otherwise, if the link is internal, then the standfirst of the linked page is returned.
  *
  * @return string
  */
 public function getText()
 {
     if (isset($this->attrs['text'])) {
         return $this->attrs['text'];
     }
     if ($this->getLink()->isInternal()) {
         $page = $this->getLink()->getPage();
         return $this->attrs['text'] = $page ? Chunk::get('text', 'standfirst', $page)->text() : '';
     }
     return $this->attrs['text'] = '';
 }
Ejemplo n.º 6
0
 public function addItem(Rss $feed, Page $page)
 {
     $tags = Helpers::getTags($page, 'Author');
     $authors = [];
     if (count($tags)) {
         foreach ($tags as $tag) {
             $authors[] = $tag->getName();
         }
     }
     $feed->item(['guid' => $page->url(), 'title' => $page->getTitle(), 'description|cdata' => Chunk::get('text', 'standfirst', $page)->text(), 'link' => $page->url(), 'pubDate' => $page->isVisible() ? $page->getVisibleFrom()->format('r') : null, 'author|cdata' => empty($authors) ? null : implode(',', $authors)]);
 }
Ejemplo n.º 7
0
 public function asHtml(Page $page)
 {
     $template = $page->getTemplate();
     View::share('chunk', function ($type, $slotname, $page = null) {
         $chunks = [];
         if ($page) {
             return Chunk::get($type, $slotname, $page);
         }
         return isset($chunks[$type][$slotname]) ? $chunks[$type][$slotname] : Chunk::edit($type, $slotname);
     });
     return $template->getView();
 }
Ejemplo n.º 8
0
 public function postSave()
 {
     $input = $this->request->input();
     if (isset($input['template'])) {
         unset($input['template']);
     }
     $chunk = ChunkFacade::create($this->page, $input);
     if ($this->request->input('template')) {
         $chunk->template($this->request->input('template'));
     }
     // This is usually defined by the page controller.
     // We need to define a variant of it incase the callback is used in teh chunk view.
     View::share('chunk', function ($type, $slotname, $page = null) {
         return ChunkFacade::get($type, $slotname, $page);
     });
     View::share('page', $this->page);
     Event::fire(new ChunkWasCreated($this->page, $chunk));
     return ['status' => $this->page->getCurrentVersion()->getStatus(), 'html' => $chunk->render()];
 }
Ejemplo n.º 9
0
 public function postSave(Request $request, Page $page)
 {
     $this->authorize('edit', $page);
     if (!$request->has('force')) {
         $latest = ChunkFacade::get($request->input('type'), $request->input('slotname'), $page);
         if ($request->input('chunkId') < $latest->getId()) {
             if ($template = $request->input('template')) {
                 $latest->template($template);
             }
             return response(['chunkId' => $latest->getId(), 'error' => 'conflict', 'html' => view('boomcms::editor.conflict')->render(), 'chunk' => $latest->render(), 'status' => $page->getCurrentVersion()->getStatus()], 500);
         }
     }
     $chunk = ChunkFacade::create($page, $request->except(['template', 'chunkId', 'force']));
     $chunk->editable(true);
     if ($template = $request->input('template')) {
         $chunk->template($template);
     }
     Router::setActivePage($page);
     View::share('page', $page);
     Event::fire(new ChunkWasCreated($page, $chunk));
     return ['status' => $page->getCurrentVersion()->getStatus(), 'html' => $chunk->render(), 'chunkId' => $chunk->getId()];
 }
Ejemplo n.º 10
0
 /**
  * Restore an older version of a page.
  *
  * Creates a new version based on the old one.
  *
  * @param Model $version
  *
  * @return Model
  */
 public function restore(Model $version)
 {
     $attrs = $version->toArray();
     $newVersion = new Model($attrs);
     $newVersion->setEditedAt(new DateTime('now'))->setEditedBy(Auth::user())->setRestoredFrom($version)->save();
     $types = Chunk::since($version);
     foreach ($types as $type => $chunks) {
         $className = Chunk::getModelName($type);
         foreach ($chunks as $chunk) {
             $old = Chunk::find($type, $chunk->slotname, $version);
             $new = new $className();
             $new->page_id = $newVersion->getPageId();
             $new->slotname = $chunk->slotname;
             $new->page_vid = $newVersion->getId();
             $new->save();
             if ($old !== null) {
                 $new->fill(array_except($old->toArray(), ['page_vid']));
                 $new->save();
             }
         }
     }
     return $newVersion;
 }
Ejemplo n.º 11
0
 public function testGetDescriptionUsesPageStandfirstAsFallback()
 {
     $page = new Page();
     Chunk::shouldReceive('get')->once()->with('text', 'standfirst', $page)->andReturn(new Text($page, ['text' => 'test standfirst', 'site_text' => 'test standfirst'], 'standfirst', false));
     $this->assertEquals('test standfirst', $page->getDescription());
 }
Ejemplo n.º 12
0
 /**
  * Reutrn the meta description for a page.
  *
  * If no page is given then the active page is used.
  *
  * The page description property will be used, if that isn't set then the page standfirst is used.
  *
  * @param null|Page $page
  *
  * @return string
  */
 public static function description(PageInterface $page = null)
 {
     $page = $page ?: Router::getActivePage();
     $description = $page->getDescription() ?: ChunkFacade::get('text', 'standfirst', $page)->text();
     return strip_tags($description);
 }
Ejemplo n.º 13
0
 /**
  * Get a description for the page.
  *
  * If no description property is set then the standfirst is used instead.
  *
  * @return string
  */
 public function getDescription()
 {
     $description = $this->{self::ATTR_DESCRIPTION};
     $description = $description != null ? $description : Chunk::get('text', 'standfirst', $this)->text();
     return strip_tags($description);
 }