Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find and replace in Footer notes. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Docx.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Docx extends \ZipArchive
const DOCUMENT_BODY_LOCATION = 'word/document.xml';
const HEADER_LOCATION = 'word/header1.xml';
const FOOTER_LOCATION = 'word/footer1.xml';
const FOOTER_NOTES_LOCATION = 'word/footnotes.xml';

/**
* @var string
Expand Down Expand Up @@ -50,6 +51,7 @@ public function replaceText($from, $to)
{
$this->replaceTextInLocation($from, $to, self::HEADER_LOCATION);
$this->replaceTextInLocation($from, $to, self::FOOTER_LOCATION);
$this->replaceTextInLocation($from, $to, self::FOOTER_NOTES_LOCATION);
$this->replaceTextInLocation($from, $to, self::DOCUMENT_BODY_LOCATION);
}

Expand All @@ -63,6 +65,7 @@ public function replaceTextInsensitive($from, $to)
{
$this->replaceTextInLocation($from, $to, self::HEADER_LOCATION, true);
$this->replaceTextInLocation($from, $to, self::FOOTER_LOCATION, true);
$this->replaceTextInLocation($from, $to, self::FOOTER_NOTES_LOCATION, true);
$this->replaceTextInLocation($from, $to, self::DOCUMENT_BODY_LOCATION, true);
}

Expand All @@ -76,7 +79,7 @@ public function replaceTextInsensitive($from, $to)
*/
public function replaceTextToImage($text, $path)
{
if (! file_exists($path)) {
if (!file_exists($path)) {
throw new \Exception('Image not exists');
}
list($width, $height, $type) = getimagesize($path);
Expand Down Expand Up @@ -106,10 +109,12 @@ private function replaceTextInLocation($from, $to, $location, $caseInsensitive =
$to = $this->fixLineBreaksInTo($to);

$message = $this->getFromName($location);
if ($caseInsensitive) {
$message = str_ireplace($from, $to, $message);
} else {
$message = str_replace($from, $to, $message);
if ($message !== false) {
if ($caseInsensitive) {
$message = str_ireplace($from, $to, $message);
} else {
$message = str_replace($from, $to, $message);
}
}

$this->addFromString($location, $message);
Expand Down Expand Up @@ -225,6 +230,6 @@ private function getNumberFromRelId($relId)
{
preg_match('!\d+!', $relId, $matches);

return (int) $matches[0];
return (int)$matches[0];
}
}