Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.5 KiB

<?php
namespace App\SearchDisplace;
use Symfony\Component\Process\Process;
class SearchAndDisplaceXML
{
protected $file;
protected $searchers;
public function __construct($file, $searchers)
{
$this->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);
}
}