@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | if (!$return['error']) { |
| 96 | 96 | // Get options for this import. |
| 97 | - $splitHeader = (int)$request->postVar('SplitHeader'); |
|
| 98 | - $keepSource = (bool)$request->postVar('KeepSource'); |
|
| 99 | - $chosenFolderID = (int)$request->postVar('ChosenFolderID'); |
|
| 100 | - $publishPages = (bool)$request->postVar('PublishPages'); |
|
| 101 | - $includeTOC = (bool)$request->postVar('IncludeTOC'); |
|
| 97 | + $splitHeader = (int) $request->postVar('SplitHeader'); |
|
| 98 | + $keepSource = (bool) $request->postVar('KeepSource'); |
|
| 99 | + $chosenFolderID = (int) $request->postVar('ChosenFolderID'); |
|
| 100 | + $publishPages = (bool) $request->postVar('PublishPages'); |
|
| 101 | + $includeTOC = (bool) $request->postVar('IncludeTOC'); |
|
| 102 | 102 | |
| 103 | 103 | // Process the document and write the page. |
| 104 | 104 | $preservedDocument = null; |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | if ($page) { |
| 155 | 155 | if ($page->Children()->Count() > 0) { |
| 156 | 156 | foreach ($page->Children() as $child) { |
| 157 | - $content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>'; |
|
| 157 | + $content .= '<li><a href="'.$child->Link().'">'.$child->Title.'</a></li>'; |
|
| 158 | 158 | } |
| 159 | - $page->Content = $content . '</ul>'; |
|
| 159 | + $page->Content = $content.'</ul>'; |
|
| 160 | 160 | } else { |
| 161 | 161 | $doc = new DOMDocument(); |
| 162 | 162 | $doc->loadHTML($page->Content); |
@@ -165,30 +165,30 @@ discard block |
||
| 165 | 165 | $h1 = $h2 = 1; |
| 166 | 166 | while ($node) { |
| 167 | 167 | if ($node instanceof DOMElement && $node->tagName == 'h1') { |
| 168 | - $content .= '<li><a href="#h1.' . $h1 . '">' . |
|
| 169 | - trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) . |
|
| 168 | + $content .= '<li><a href="#h1.'.$h1.'">'. |
|
| 169 | + trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))). |
|
| 170 | 170 | '</a></li>'; |
| 171 | 171 | $node->setAttributeNode(new DOMAttr("id", "h1.".$h1)); |
| 172 | 172 | $h1++; |
| 173 | 173 | } elseif ($node instanceof DOMElement && $node->tagName == 'h2') { |
| 174 | - $content .= '<li class="menu-h2"><a href="#h2.' . $h2 . '">' . |
|
| 175 | - trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) . |
|
| 174 | + $content .= '<li class="menu-h2"><a href="#h2.'.$h2.'">'. |
|
| 175 | + trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))). |
|
| 176 | 176 | '</a></li>'; |
| 177 | 177 | $node->setAttributeNode(new DOMAttr("id", "h2.".$h2)); |
| 178 | 178 | $h2++; |
| 179 | 179 | } |
| 180 | 180 | $node = $node->nextSibling; |
| 181 | 181 | } |
| 182 | - $page->Content = $content . '</ul>' . $doc->saveHTML(); |
|
| 182 | + $page->Content = $content.'</ul>'.$doc->saveHTML(); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Add in the link to the original document, if provided. |
| 186 | 186 | if ($preservedDocument) { |
| 187 | - $page->Content = '<a href="' . |
|
| 188 | - $preservedDocument->Link() . |
|
| 189 | - '" title="download original document">download original document (' . |
|
| 190 | - $preservedDocument->getSize() . |
|
| 191 | - ')</a>' . |
|
| 187 | + $page->Content = '<a href="'. |
|
| 188 | + $preservedDocument->Link(). |
|
| 189 | + '" title="download original document">download original document ('. |
|
| 190 | + $preservedDocument->getSize(). |
|
| 191 | + ')</a>'. |
|
| 192 | 192 | $page->Content; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | unset($this->unusedChildren[$page->ID]); |
| 248 | - file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode)); |
|
| 248 | + file_put_contents(ASSETS_PATH.'/index-'.$sort.'.html', $this->getBodyText($subdoc, $subnode)); |
|
| 249 | 249 | |
| 250 | 250 | if ($sort) { |
| 251 | 251 | $page->Sort = $sort; |
@@ -315,20 +315,20 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | // make sure any images are added as Image records with a relative link to assets |
| 317 | 317 | $chosenFolder = ($this->chosenFolderID) ? DataObject::get_by_id(Folder::class, $this->chosenFolderID) : null; |
| 318 | - $folderName = ($chosenFolder) ? '/' . $chosenFolder->Name : ''; |
|
| 318 | + $folderName = ($chosenFolder) ? '/'.$chosenFolder->Name : ''; |
|
| 319 | 319 | $imgs = $xpath->query('//img'); |
| 320 | 320 | for ($i = 0; $i < $imgs->length; $i++) { |
| 321 | 321 | $img = $imgs->item($i); |
| 322 | - $originalPath = 'assets/' . $folderName . '/' . $img->getAttribute('src'); |
|
| 322 | + $originalPath = 'assets/'.$folderName.'/'.$img->getAttribute('src'); |
|
| 323 | 323 | $name = FileNameFilter::create()->filter(basename($originalPath)); |
| 324 | 324 | |
| 325 | 325 | $image = Image::get()->filter([ |
| 326 | 326 | 'Name' => $name, |
| 327 | - 'ParentID' => (int)$chosenFolderID |
|
| 327 | + 'ParentID' => (int) $chosenFolderID |
|
| 328 | 328 | ])->first(); |
| 329 | 329 | if (!($image && $image->exists())) { |
| 330 | 330 | $image = Image::create(); |
| 331 | - $image->ParentID = (int)$chosenFolderID; |
|
| 331 | + $image->ParentID = (int) $chosenFolderID; |
|
| 332 | 332 | $image->Name = $name; |
| 333 | 333 | $image->write(); |
| 334 | 334 | } |
@@ -364,8 +364,7 @@ discard block |
||
| 364 | 364 | if ($parenttag) { |
| 365 | 365 | $parent = $doc->createElement($parenttag); |
| 366 | 366 | $node->nextSibling ? |
| 367 | - $node->parentNode->insertBefore($parent, $node->nextSibling) : |
|
| 368 | - $node->parentNode->appendChild($parent); |
|
| 367 | + $node->parentNode->insertBefore($parent, $node->nextSibling) : $node->parentNode->appendChild($parent); |
|
| 369 | 368 | } |
| 370 | 369 | |
| 371 | 370 | while ($node->firstChild) { |
@@ -399,7 +398,7 @@ discard block |
||
| 399 | 398 | // Empty paragraphs |
| 400 | 399 | '//p[not(descendant-or-self::text() | descendant-or-self::img)]', |
| 401 | 400 | // Empty headers |
| 402 | - '//*[' . implode(' | ', $headingXPath) . '][not(descendant-or-self::text() | descendant-or-self::img)]', |
|
| 401 | + '//*['.implode(' | ', $headingXPath).'][not(descendant-or-self::text() | descendant-or-self::img)]', |
|
| 403 | 402 | // Anchors |
| 404 | 403 | '//a[not(@href)]', |
| 405 | 404 | // BR tags |
@@ -432,7 +431,7 @@ discard block |
||
| 432 | 431 | |
| 433 | 432 | $documentImporterFieldError = false; |
| 434 | 433 | |
| 435 | - $documentImporterFieldErrorHandler = function ( |
|
| 434 | + $documentImporterFieldErrorHandler = function( |
|
| 436 | 435 | $errno, |
| 437 | 436 | $errstr, |
| 438 | 437 | $errfile, |
@@ -457,7 +456,7 @@ discard block |
||
| 457 | 456 | $sort = 1; |
| 458 | 457 | if ($splitHeader == 1 || $splitHeader == 2) { |
| 459 | 458 | while ($node && !$documentImporterFieldError) { |
| 460 | - if ($node instanceof DOMElement && $node->tagName == 'h' . $splitHeader) { |
|
| 459 | + if ($node instanceof DOMElement && $node->tagName == 'h'.$splitHeader) { |
|
| 461 | 460 | if ($subnode->hasChildNodes()) { |
| 462 | 461 | $this->writeContent($subtitle, $subdoc, $subnode, $sort, $publishPages); |
| 463 | 462 | $sort++; |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | ]; |
| 66 | 66 | foreach ($settingsFields as $fieldName => $className) { |
| 67 | 67 | $field = $fields->fieldByName( |
| 68 | - 'DocumentConversionSettings-' . $fieldName |
|
| 68 | + 'DocumentConversionSettings-'.$fieldName |
|
| 69 | 69 | ); |
| 70 | 70 | $this->assertInstanceOf($className, $field); |
| 71 | 71 | $this->assertContains('no-change-track', $field->extraClass()); |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | $fields->findOrMakeTab( |
| 28 | 28 | 'Root.Import', |
| 29 | - _t(__CLASS__ . '.ImportTab', 'Import') |
|
| 29 | + _t(__CLASS__.'.ImportTab', 'Import') |
|
| 30 | 30 | ); |
| 31 | 31 | $fields->addFieldToTab('Root.Import', SettingsField::create()); |
| 32 | 32 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | return $fromConfig; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $fromEnv = Environment::getEnv('DOCVERT_' . strtoupper($detail)); |
|
| 91 | + $fromEnv = Environment::getEnv('DOCVERT_'.strtoupper($detail)); |
|
| 92 | 92 | if ($fromEnv) { |
| 93 | 93 | return $fromEnv; |
| 94 | 94 | } |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | ]); |
| 148 | 148 | |
| 149 | 149 | $chosenFolder = ($this->chosenFolderID) ? DataObject::get_by_id(Folder::class, $this->chosenFolderID) : null; |
| 150 | - $folderName = ($chosenFolder) ? '/' . $chosenFolder->Name : ''; |
|
| 150 | + $folderName = ($chosenFolder) ? '/'.$chosenFolder->Name : ''; |
|
| 151 | 151 | $outname = tempnam(ASSETS_PATH, 'convert'); |
| 152 | - $outzip = $outname . '.zip'; |
|
| 152 | + $outzip = $outname.'.zip'; |
|
| 153 | 153 | $out = fopen($outzip, 'w'); |
| 154 | 154 | curl_setopt($ch, CURLOPT_FILE, $out); |
| 155 | 155 | $returnValue = curl_exec($ch); |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | if (!$returnValue || ($status != 200)) { |
| 162 | 162 | return ['error' => _t( |
| 163 | - __CLASS__ . '.SERVERUNREACHABLE', |
|
| 164 | - 'Could not contact document conversion server. Please try again later ' . |
|
| 163 | + __CLASS__.'.SERVERUNREACHABLE', |
|
| 164 | + 'Could not contact document conversion server. Please try again later '. |
|
| 165 | 165 | 'or contact your system administrator.', |
| 166 | 166 | 'Document Converter process Word documents into HTML.' |
| 167 | 167 | )]; |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $zip = new ZipArchive(); |
| 173 | 173 | |
| 174 | 174 | if ($zip->open($outzip)) { |
| 175 | - $zip->extractTo(ASSETS_PATH .$folderName); |
|
| 175 | + $zip->extractTo(ASSETS_PATH.$folderName); |
|
| 176 | 176 | $zip->close(); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -180,17 +180,17 @@ discard block |
||
| 180 | 180 | unlink($outname); |
| 181 | 181 | unlink($outzip); |
| 182 | 182 | |
| 183 | - if (!file_exists(ASSETS_PATH . $folderName . '/index.html')) { |
|
| 183 | + if (!file_exists(ASSETS_PATH.$folderName.'/index.html')) { |
|
| 184 | 184 | return ['error' => _t( |
| 185 | - __CLASS__ . '.PROCESSFAILED', |
|
| 185 | + __CLASS__.'.PROCESSFAILED', |
|
| 186 | 186 | 'Could not process document, please double-check you uploaded a .doc or .docx format.', |
| 187 | 187 | 'Document Converter processes Word documents into HTML.' |
| 188 | 188 | )]; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - $content = file_get_contents(ASSETS_PATH . $folderName . '/index.html'); |
|
| 191 | + $content = file_get_contents(ASSETS_PATH.$folderName.'/index.html'); |
|
| 192 | 192 | |
| 193 | - unlink(ASSETS_PATH . $folderName . '/index.html'); |
|
| 193 | + unlink(ASSETS_PATH.$folderName.'/index.html'); |
|
| 194 | 194 | |
| 195 | 195 | return $content; |
| 196 | 196 | } |
@@ -45,50 +45,50 @@ |
||
| 45 | 45 | $fields = FieldList::create([ |
| 46 | 46 | LiteralField::create( |
| 47 | 47 | 'FileWarningHeader', |
| 48 | - '<div class="alert alert-warning">' . _t( |
|
| 49 | - __CLASS__ . '.FileWarningHeader', |
|
| 48 | + '<div class="alert alert-warning">'._t( |
|
| 49 | + __CLASS__.'.FileWarningHeader', |
|
| 50 | 50 | 'Warning: import will remove all content and subpages of this page.' |
| 51 | - ) . '</div>', |
|
| 51 | + ).'</div>', |
|
| 52 | 52 | 4 |
| 53 | 53 | ), |
| 54 | 54 | $splitHeader = DropdownField::create( |
| 55 | 55 | 'DocumentConversionSettings-SplitHeader', |
| 56 | 56 | _t( |
| 57 | - __CLASS__ . '.SplitHeader', |
|
| 57 | + __CLASS__.'.SplitHeader', |
|
| 58 | 58 | 'Split document into pages' |
| 59 | 59 | ), |
| 60 | 60 | [ |
| 61 | - 0 => _t(__CLASS__ . '.No', 'no'), |
|
| 62 | - 1 => _t(__CLASS__ . '.EachH1', 'for each heading 1'), |
|
| 63 | - 2 => _t(__CLASS__ . '.EachH2', 'for each heading 2') |
|
| 61 | + 0 => _t(__CLASS__.'.No', 'no'), |
|
| 62 | + 1 => _t(__CLASS__.'.EachH1', 'for each heading 1'), |
|
| 63 | + 2 => _t(__CLASS__.'.EachH2', 'for each heading 2') |
|
| 64 | 64 | ] |
| 65 | 65 | ), |
| 66 | 66 | $keepSource = CheckboxField::create( |
| 67 | 67 | 'DocumentConversionSettings-KeepSource', |
| 68 | 68 | _t( |
| 69 | - __CLASS__ . '.KeepSource', |
|
| 69 | + __CLASS__.'.KeepSource', |
|
| 70 | 70 | 'Keep the original document. Adds a link to it on TOC, if enabled.' |
| 71 | 71 | ) |
| 72 | 72 | ), |
| 73 | 73 | $chosenFolderID = TreeDropdownField::create( |
| 74 | 74 | 'DocumentConversionSettings-ChosenFolderID', |
| 75 | - _t(__CLASS__ . '.ChooseFolder', 'Choose a folder to save this file'), |
|
| 75 | + _t(__CLASS__.'.ChooseFolder', 'Choose a folder to save this file'), |
|
| 76 | 76 | Folder::class |
| 77 | 77 | ), |
| 78 | 78 | $includeTOC = CheckboxField::create( |
| 79 | 79 | 'DocumentConversionSettings-IncludeTOC', |
| 80 | - _t(__CLASS__ . '.IncludeTOC', 'Replace this page with a Table of Contents.') |
|
| 80 | + _t(__CLASS__.'.IncludeTOC', 'Replace this page with a Table of Contents.') |
|
| 81 | 81 | ), |
| 82 | 82 | $publishPages = CheckboxField::create( |
| 83 | 83 | 'DocumentConversionSettings-PublishPages', |
| 84 | 84 | _t( |
| 85 | - __CLASS__ . '.publishPages', |
|
| 85 | + __CLASS__.'.publishPages', |
|
| 86 | 86 | 'Publish modified pages (not recommended unless you are sure about the conversion outcome)' |
| 87 | 87 | ) |
| 88 | 88 | ), |
| 89 | 89 | $this->innerField = ImportField::create( |
| 90 | 90 | 'ImportedFromFile', |
| 91 | - _t(__CLASS__ . '.ImportedFromFile', 'Import content from a word document') |
|
| 91 | + _t(__CLASS__.'.ImportedFromFile', 'Import content from a word document') |
|
| 92 | 92 | ) |
| 93 | 93 | ]); |
| 94 | 94 | |