@@ -34,11 +34,15 @@ discard block |
||
| 34 | 34 | * Process the document immediately upon upload. |
| 35 | 35 | */ |
| 36 | 36 | public function upload(SS_HTTPRequest $request) { |
| 37 | - if($this->isDisabled() || $this->isReadonly()) return $this->httpError(403); |
|
| 37 | + if($this->isDisabled() || $this->isReadonly()) { |
|
| 38 | + return $this->httpError(403); |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | // Protect against CSRF on destructive action |
| 40 | 42 | $token = $this->getForm()->getSecurityToken(); |
| 41 | - if(!$token->checkRequest($request)) return $this->httpError(400); |
|
| 43 | + if(!$token->checkRequest($request)) { |
|
| 44 | + return $this->httpError(400); |
|
| 45 | + } |
|
| 42 | 46 | |
| 43 | 47 | $name = $this->getName(); |
| 44 | 48 | $tmpfile = $request->postVar($name); |
@@ -65,7 +69,9 @@ discard block |
||
| 65 | 69 | |
| 66 | 70 | // Process the document and write the page. |
| 67 | 71 | $preservedDocument = null; |
| 68 | - if ($keepSource) $preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID); |
|
| 72 | + if ($keepSource) { |
|
| 73 | + $preservedDocument = $this->preserveSourceDocument($tmpfile, $chosenFolderID); |
|
| 74 | + } |
|
| 69 | 75 | |
| 70 | 76 | $importResult = $this->importFromPOST($tmpfile, $splitHeader, $publishPages, $chosenFolderID); |
| 71 | 77 | if (is_array($importResult) && isset($importResult['error'])) { |
@@ -116,7 +122,7 @@ discard block |
||
| 116 | 122 | $content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>'; |
| 117 | 123 | } |
| 118 | 124 | $page->Content = $content . '</ul>'; |
| 119 | - } else { |
|
| 125 | + } else { |
|
| 120 | 126 | $doc = new DOMDocument(); |
| 121 | 127 | $doc->loadHTML($page->Content); |
| 122 | 128 | $body = $doc->getElementsByTagName('body')->item(0); |
@@ -145,7 +151,9 @@ discard block |
||
| 145 | 151 | |
| 146 | 152 | // Store the result |
| 147 | 153 | $page->write(); |
| 148 | - if($publishPages) $page->doPublish(); |
|
| 154 | + if($publishPages) { |
|
| 155 | + $page->doPublish(); |
|
| 156 | + } |
|
| 149 | 157 | } |
| 150 | 158 | } |
| 151 | 159 | |
@@ -191,16 +199,22 @@ discard block |
||
| 191 | 199 | unset($this->unusedChildren[$page->ID]); |
| 192 | 200 | file_put_contents(ASSETS_PATH . '/index-' . $sort . '.html', $this->getBodyText($subdoc, $subnode)); |
| 193 | 201 | |
| 194 | - if ($sort) $page->Sort = $sort; |
|
| 202 | + if ($sort) { |
|
| 203 | + $page->Sort = $sort; |
|
| 204 | + } |
|
| 195 | 205 | $page->Content = $this->getBodyText($subdoc, $subnode); |
| 196 | 206 | $page->write(); |
| 197 | - if($publishPages) $page->doPublish(); |
|
| 207 | + if($publishPages) { |
|
| 208 | + $page->doPublish(); |
|
| 209 | + } |
|
| 198 | 210 | } else { |
| 199 | 211 | // Write to the master page. |
| 200 | 212 | $record->Content = $this->getBodyText($subdoc, $subnode); |
| 201 | 213 | $record->write(); |
| 202 | 214 | |
| 203 | - if($publishPages) $record->doPublish(); |
|
| 215 | + if($publishPages) { |
|
| 216 | + $record->doPublish(); |
|
| 217 | + } |
|
| 204 | 218 | } |
| 205 | 219 | |
| 206 | 220 | } |
@@ -286,7 +300,9 @@ discard block |
||
| 286 | 300 | } |
| 287 | 301 | |
| 288 | 302 | $nodes = array(); |
| 289 | - foreach($xpath->query($rule) as $node) $nodes[] = $node; |
|
| 303 | + foreach($xpath->query($rule) as $node) { |
|
| 304 | + $nodes[] = $node; |
|
| 305 | + } |
|
| 290 | 306 | |
| 291 | 307 | foreach($nodes as $node) { |
| 292 | 308 | $parent = $node->parentNode; |
@@ -296,7 +312,9 @@ discard block |
||
| 296 | 312 | $node->nextSibling ? $node->parentNode->insertBefore($parent, $node->nextSibling) : $node->parentNode->appendChild($parent); |
| 297 | 313 | } |
| 298 | 314 | |
| 299 | - while($node->firstChild) $parent->appendChild($node->firstChild); |
|
| 315 | + while($node->firstChild) { |
|
| 316 | + $parent->appendChild($node->firstChild); |
|
| 317 | + } |
|
| 300 | 318 | $node->parentNode->removeChild($node); |
| 301 | 319 | } |
| 302 | 320 | } |
@@ -324,10 +342,15 @@ discard block |
||
| 324 | 342 | // First get all the nodes. Need to build array, as they'll disappear from the nodelist while we're deleteing them, causing the indexing |
| 325 | 343 | // to screw up. |
| 326 | 344 | $nodes = array(); |
| 327 | - foreach($xpath->query($query) as $node) $nodes[] = $node; |
|
| 345 | + foreach($xpath->query($query) as $node) { |
|
| 346 | + $nodes[] = $node; |
|
| 347 | + } |
|
| 328 | 348 | |
| 329 | 349 | // Then remove them all |
| 330 | - foreach ($nodes as $node) { if ($node->parentNode) $node->parentNode->removeChild($node); } |
|
| 350 | + foreach ($nodes as $node) { if ($node->parentNode) { |
|
| 351 | + $node->parentNode->removeChild($node); |
|
| 352 | + } |
|
| 353 | + } |
|
| 331 | 354 | } |
| 332 | 355 | |
| 333 | 356 | // Now split the document into portions by H1 |
@@ -16,8 +16,12 @@ |
||
| 16 | 16 | * @param $children FieldSet/array Any additional children. |
| 17 | 17 | */ |
| 18 | 18 | public function __construct($children = null) { |
| 19 | - if (is_string($children)) throw new InvalidArgumentException('DocumentImportField::__construct does not accept a name as its parameter, it defaults to "ImportedFromFile" instead. Use DocumentImportField::getInnerField()->setName() if you want to change it.'); |
|
| 20 | - if ($children) throw new InvalidArgumentException('DocumentImportField::__construct provides its own fields and does not accept additional children.'); |
|
| 19 | + if (is_string($children)) { |
|
| 20 | + throw new InvalidArgumentException('DocumentImportField::__construct does not accept a name as its parameter, it defaults to "ImportedFromFile" instead. Use DocumentImportField::getInnerField()->setName() if you want to change it.'); |
|
| 21 | + } |
|
| 22 | + if ($children) { |
|
| 23 | + throw new InvalidArgumentException('DocumentImportField::__construct provides its own fields and does not accept additional children.'); |
|
| 24 | + } |
|
| 21 | 25 | |
| 22 | 26 | // Add JS specific to this field. |
| 23 | 27 | Requirements::javascript('documentconverter/javascript/DocumentImportField.js'); |