file = $file; $this->searchers = $searchers; } public function execute() { $this->applySD(); $this->convertToOdt(); } protected function convertToOdt() { (new Process(['soffice', '--convert-to', 'odt', $this->file, '--outdir', storage_path('app/tmp/')]))->run(); } protected function applySD() { $dom = new \DOMDocument(); $dom->load($this->file); foreach($dom->getElementsByTagName('p') as $p) { $is_image = false; if($p->childNodes) { foreach($p->childNodes as $child) { if(isset($child->tagName) && $child->tagName == 'draw:frame') { $is_image = true; } } } if(!$is_image) { $search = new SearchAndDisplace( stripslashes($p->textContent), [ 'searchers' => $this->searchers, ], false, true ); $changed = $search->execute(); if(!$changed) { continue; } $p->textContent = $changed['content']; } } $dom->save($this->file); } }