|
@ -5,6 +5,7 @@ namespace App\SearchDisplace; |
|
|
use App\SearchDisplace\Documents\DocumentFile; |
|
|
use App\SearchDisplace\Documents\DocumentFile; |
|
|
use Illuminate\Support\Facades\Storage; |
|
|
use Illuminate\Support\Facades\Storage; |
|
|
use App\SearchDisplace\Convertor\Convertor; |
|
|
use App\SearchDisplace\Convertor\Convertor; |
|
|
|
|
|
use DOMDocument; |
|
|
|
|
|
|
|
|
class SearchAndDisplaceXML |
|
|
class SearchAndDisplaceXML |
|
|
{ |
|
|
{ |
|
@ -12,6 +13,7 @@ class SearchAndDisplaceXML |
|
|
protected $searchers; |
|
|
protected $searchers; |
|
|
protected $storage; |
|
|
protected $storage; |
|
|
protected $searchOnly; |
|
|
protected $searchOnly; |
|
|
|
|
|
protected $markedStyleCreated; |
|
|
|
|
|
|
|
|
public function __construct($file, $searchers, $searchOnly) |
|
|
public function __construct($file, $searchers, $searchOnly) |
|
|
{ |
|
|
{ |
|
@ -19,6 +21,7 @@ class SearchAndDisplaceXML |
|
|
$this->searchers = $searchers; |
|
|
$this->searchers = $searchers; |
|
|
$this->storage = Storage::disk('local'); |
|
|
$this->storage = Storage::disk('local'); |
|
|
$this->searchOnly = $searchOnly; |
|
|
$this->searchOnly = $searchOnly; |
|
|
|
|
|
$this->markedStyleCreated = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function execute() |
|
|
public function execute() |
|
@ -89,7 +92,8 @@ class SearchAndDisplaceXML |
|
|
* |
|
|
* |
|
|
* @return void |
|
|
* @return void |
|
|
*/ |
|
|
*/ |
|
|
protected function replace($content, $element, $dom) { |
|
|
|
|
|
|
|
|
protected function replace($content, $element, $dom) |
|
|
|
|
|
{ |
|
|
$search = new SearchAndDisplace( |
|
|
$search = new SearchAndDisplace( |
|
|
stripslashes($content), |
|
|
stripslashes($content), |
|
|
[ |
|
|
[ |
|
@ -117,17 +121,62 @@ class SearchAndDisplaceXML |
|
|
|
|
|
|
|
|
foreach($indexes[$searcher] as $change) { |
|
|
foreach($indexes[$searcher] as $change) { |
|
|
$first = substr($content, 0, $change['start']); |
|
|
$first = substr($content, 0, $change['start']); |
|
|
$changed = "<mark>" . substr($content, $change['start'], $change['end'] - $change['start'] + 1) . "</mark>"; |
|
|
|
|
|
|
|
|
$changed = substr($content, $change['start'], $change['end'] - $change['start'] + 1); |
|
|
$last = substr($content, $change['end'] + 1); |
|
|
$last = substr($content, $change['end'] + 1); |
|
|
|
|
|
|
|
|
$element->textContent = $first; |
|
|
$element->textContent = $first; |
|
|
$changed = $dom->createElement("text:span", $changed); |
|
|
$changed = $dom->createElement("text:span", $changed); |
|
|
$last = $dom->createElement("text:span", $last); |
|
|
$last = $dom->createElement("text:span", $last); |
|
|
// $changed->setAttribute('style', 'background-color: red');
|
|
|
|
|
|
|
|
|
//text:style-name="mark"
|
|
|
|
|
|
$changed->setAttribute('text:style-name', 'mark'); |
|
|
$element->appendChild($changed); |
|
|
$element->appendChild($changed); |
|
|
$element->appendChild($last); |
|
|
$element->appendChild($last); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!$this->markedStyleCreated) { |
|
|
|
|
|
$this->createMarkedStyle($dom); |
|
|
|
|
|
} |
|
|
|
|
|
$this->markedStyleCreated = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Create marked style for browser preview |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
private function createMarkedStyle($dom) |
|
|
|
|
|
{ |
|
|
|
|
|
$style = $dom->createElement("style:style"); |
|
|
|
|
|
$style->setAttribute("style:name", 'mark'); |
|
|
|
|
|
$style->setAttribute("style:family", 'text'); |
|
|
|
|
|
|
|
|
|
|
|
$child = $dom->createElement('style:text-properties'); |
|
|
|
|
|
$child->setAttribute("officeooo:rsid", '0014890a'); |
|
|
|
|
|
$child->setAttribute("fo:background-color", '#ffff00'); |
|
|
|
|
|
|
|
|
|
|
|
$style->appendChild($child); |
|
|
|
|
|
|
|
|
|
|
|
$dom->getElementsByTagName('automatic-styles')->item(0)->appendChild($style); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Remove marked style used in browser and convert XML file to original file type |
|
|
|
|
|
* |
|
|
|
|
|
* @param $type file type |
|
|
|
|
|
* @param $file absolute file path |
|
|
|
|
|
* |
|
|
|
|
|
* @return string $path |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function prepareForDownload($type, $file) |
|
|
|
|
|
{ |
|
|
|
|
|
// remove marked style from XML
|
|
|
|
|
|
$dom = new DOMDocument(); |
|
|
|
|
|
$dom->load($file); |
|
|
|
|
|
$style = $dom->getElementsByTagName('automatic-styles')->item(0); |
|
|
|
|
|
$style->removeChild($style->lastChild); |
|
|
|
|
|
$dom->save($file); |
|
|
|
|
|
|
|
|
|
|
|
return Convertor::convert($type, $file, true); |
|
|
|
|
|
} |
|
|
} |
|
|
} |