Passed
Push — master ( 9fb1d9...8460a0 )
by Maxence
02:20
created

PicoService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * CMS Pico - Integration of Pico within your files to create websites.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\CMSPico\Service;
28
29
use OCA\CMSPico\Model\Website;
30
use Pico;
31
32
class PicoService {
33
34
	const DIR_CONFIG = 'config/';
35
	const DIR_PLUGINS = 'plugins/';
36
	const DIR_THEMES = 'themes/';
37
38
	private $userId;
39
	/** @var MiscService */
40
	private $miscService;
41
42
	/**
43
	 * PicoService constructor.
44
	 *
45
	 * @param string $userId
46
	 * @param MiscService $miscService
47
	 */
48
	function __construct($userId, MiscService $miscService) {
49
		$this->userId = $userId;
50
		$this->miscService = $miscService;
51
	}
52
53
54
	/**
55
	 * @param Website $website
56
	 *
57
	 * @return string
58
	 */
59
	public function getContent(Website $website) {
60
61
		$pico = new Pico(
62
			$website->getAbsolutePath(),
63
			self::DIR_CONFIG, self::DIR_PLUGINS, self::DIR_THEMES
64
		);
65
66
		$pico->run();
67
68
		$absolutePath = $this->getAbsolutePathFromPage($pico);
69
		$website->contentMustBeLocal($absolutePath);
70
		$website->viewerMustHaveAccess($absolutePath, $pico->getFileMeta());
71
72
		return $pico->getFileContent();
73
	}
74
75
76
	/**
77
	 * @param Pico $pico
78
	 *
79
	 * @return string
80
	 */
81
	private function getAbsolutePathFromPage(Pico $pico) {
82
		return $pico->getConfig()['content_dir'] . $pico->getCurrentPage()['id'] . '.md';
83
	}
84
85
}