@@ 164-166 (lines=3) @@ | ||
161 | strpos('.'.$filenameParts[sizeof($filenameParts)-2],$this->paperhive_rev_extension) === false)){ |
|
162 | // File needs correction, since been renamed or is obsolete |
|
163 | $revision = $this->loadPaperHiveIdFromFile($dir, $filename); |
|
164 | if ($revision === false){ |
|
165 | return new DataResponse(['message' => (string)$this->l->t('File is obsolete, incorrectly renamed or cannot be read.')], Http::STATUS_BAD_REQUEST); |
|
166 | } |
|
167 | } else { |
|
168 | // File has correct format, and revision is the second extension |
|
169 | // Add extension dot since explode removed it and replace rev extension with empty string |
|
@@ 255-258 (lines=4) @@ | ||
252 | public function generatePaperHiveDocument($dir, $bookID) { |
|
253 | // Send request to PaperHive |
|
254 | $paperHiveString = $this->fetchDiscussions($bookID); |
|
255 | if ($paperHiveString === false) { |
|
256 | $message = (string)$this->l->t('Problem connecting to PaperHive.'); |
|
257 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
258 | } |
|
259 | $paperHiveDiscussions = json_decode($paperHiveString, true); |
|
260 | $discussionCount = -1; |
|
261 | if (json_last_error() === JSON_ERROR_NONE && isset($paperHiveDiscussions['discussions'])) { |
|
@@ 266-269 (lines=4) @@ | ||
263 | } |
|
264 | ||
265 | $paperHiveString = $this->fetchDocument($bookID); |
|
266 | if ($paperHiveString === false) { |
|
267 | $message = (string)$this->l->t('Problem connecting to PaperHive.'); |
|
268 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
269 | } |
|
270 | $paperHiveObject = json_decode($paperHiveString, true); |
|
271 | ||
272 | ||
@@ 285-288 (lines=4) @@ | ||
282 | ||
283 | try { |
|
284 | $exists = $this->view->file_exists($path); |
|
285 | if ($exists) { |
|
286 | $message = (string) $this->l->t('The file already exists.'); |
|
287 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
288 | } |
|
289 | $filecontents = iconv(mb_detect_encoding($paperHiveString), "UTF-8", $paperHiveString); |
|
290 | try { |
|
291 | $this->view->file_put_contents($path, $filecontents); |
|
@@ 308-311 (lines=4) @@ | ||
305 | $message = (string)$this->l->t('An internal server error occurred.'); |
|
306 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
307 | } |
|
308 | } else { |
|
309 | $message = (string)$this->l->t('Received wrong response from PaperHive.'); |
|
310 | return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST); |
|
311 | } |
|
312 | } |
|
313 | ||
314 | /** |