Completed
Pull Request — master (#8051)
by Julius
17:00
created
lib/private/Template/Base.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -31,161 +31,161 @@
 block discarded – undo
31 31
 use OCP\Defaults;
32 32
 
33 33
 class Base {
34
-	private $template; // The template
35
-	private $vars; // Vars
36
-
37
-	/** @var \OCP\IL10N */
38
-	private $l10n;
39
-
40
-	/** @var Defaults */
41
-	private $theme;
42
-
43
-	/**
44
-	 * @param string $template
45
-	 * @param string $requestToken
46
-	 * @param \OCP\IL10N $l10n
47
-	 * @param Defaults $theme
48
-	 */
49
-	public function __construct($template, $requestToken, $l10n, $theme ) {
50
-		$this->vars = array();
51
-		$this->vars['requesttoken'] = $requestToken;
52
-		$this->l10n = $l10n;
53
-		$this->template = $template;
54
-		$this->theme = $theme;
55
-	}
56
-
57
-	/**
58
-	 * @param string $serverRoot
59
-	 * @param string|false $app_dir
60
-	 * @param string $theme
61
-	 * @param string $app
62
-	 * @return string[]
63
-	 */
64
-	protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
65
-		// Check if the app is in the app folder or in the root
66
-		if( file_exists($app_dir.'/templates/' )) {
67
-			return [
68
-				$serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
69
-				$app_dir.'/templates/',
70
-			];
71
-		}
72
-		return [
73
-			$serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
74
-			$serverRoot.'/'.$app.'/templates/',
75
-		];
76
-	}
77
-
78
-	/**
79
-	 * @param string $serverRoot
80
-	 * @param string $theme
81
-	 * @return string[]
82
-	 */
83
-	protected function getCoreTemplateDirs($theme, $serverRoot) {
84
-		return [
85
-			$serverRoot.'/themes/'.$theme.'/core/templates/',
86
-			$serverRoot.'/core/templates/',
87
-		];
88
-	}
89
-
90
-	/**
91
-	 * Assign variables
92
-	 * @param string $key key
93
-	 * @param array|bool|integer|string $value value
94
-	 * @return bool
95
-	 *
96
-	 * This function assigns a variable. It can be accessed via $_[$key] in
97
-	 * the template.
98
-	 *
99
-	 * If the key existed before, it will be overwritten
100
-	 */
101
-	public function assign( $key, $value) {
102
-		$this->vars[$key] = $value;
103
-		return true;
104
-	}
105
-
106
-	/**
107
-	 * Appends a variable
108
-	 * @param string $key key
109
-	 * @param mixed $value value
110
-	 * @return boolean|null
111
-	 *
112
-	 * This function assigns a variable in an array context. If the key already
113
-	 * exists, the value will be appended. It can be accessed via
114
-	 * $_[$key][$position] in the template.
115
-	 */
116
-	public function append( $key, $value ) {
117
-		if( array_key_exists( $key, $this->vars )) {
118
-			$this->vars[$key][] = $value;
119
-		}
120
-		else{
121
-			$this->vars[$key] = array( $value );
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Prints the proceeded template
127
-	 * @return bool
128
-	 *
129
-	 * This function proceeds the template and prints its output.
130
-	 */
131
-	public function printPage() {
132
-		$data = $this->fetchPage();
133
-		if( $data === false ) {
134
-			return false;
135
-		}
136
-		else{
137
-			print $data;
138
-			return true;
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Process the template
144
-	 *
145
-	 * @param array|null $additionalParams
146
-	 * @return string This function processes the template.
147
-	 *
148
-	 * This function processes the template.
149
-	 */
150
-	public function fetchPage($additionalParams = null) {
151
-		return $this->load($this->template, $additionalParams);
152
-	}
153
-
154
-	/**
155
-	 * doing the actual work
156
-	 *
157
-	 * @param string $file
158
-	 * @param array|null $additionalParams
159
-	 * @return string content
160
-	 *
161
-	 * Includes the template file, fetches its output
162
-	 */
163
-	protected function load($file, $additionalParams = null) {
164
-		// Register the variables
165
-		$_ = $this->vars;
166
-		$l = $this->l10n;
167
-		$theme = $this->theme;
168
-
169
-		if(!is_null($additionalParams)) {
170
-			$_ = array_merge( $additionalParams, $this->vars );
171
-			foreach ($_ as $var => $value) {
172
-				${$var} = $value;
173
-			}
174
-		}
175
-
176
-		// Include
177
-		ob_start();
178
-		try {
179
-			include $file;
180
-			$data = ob_get_contents();
181
-		} catch (\Exception $e) {
182
-			@ob_end_clean();
183
-			throw $e;
184
-		}
185
-		@ob_end_clean();
186
-
187
-		// Return data
188
-		return $data;
189
-	}
34
+    private $template; // The template
35
+    private $vars; // Vars
36
+
37
+    /** @var \OCP\IL10N */
38
+    private $l10n;
39
+
40
+    /** @var Defaults */
41
+    private $theme;
42
+
43
+    /**
44
+     * @param string $template
45
+     * @param string $requestToken
46
+     * @param \OCP\IL10N $l10n
47
+     * @param Defaults $theme
48
+     */
49
+    public function __construct($template, $requestToken, $l10n, $theme ) {
50
+        $this->vars = array();
51
+        $this->vars['requesttoken'] = $requestToken;
52
+        $this->l10n = $l10n;
53
+        $this->template = $template;
54
+        $this->theme = $theme;
55
+    }
56
+
57
+    /**
58
+     * @param string $serverRoot
59
+     * @param string|false $app_dir
60
+     * @param string $theme
61
+     * @param string $app
62
+     * @return string[]
63
+     */
64
+    protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
65
+        // Check if the app is in the app folder or in the root
66
+        if( file_exists($app_dir.'/templates/' )) {
67
+            return [
68
+                $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
69
+                $app_dir.'/templates/',
70
+            ];
71
+        }
72
+        return [
73
+            $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
74
+            $serverRoot.'/'.$app.'/templates/',
75
+        ];
76
+    }
77
+
78
+    /**
79
+     * @param string $serverRoot
80
+     * @param string $theme
81
+     * @return string[]
82
+     */
83
+    protected function getCoreTemplateDirs($theme, $serverRoot) {
84
+        return [
85
+            $serverRoot.'/themes/'.$theme.'/core/templates/',
86
+            $serverRoot.'/core/templates/',
87
+        ];
88
+    }
89
+
90
+    /**
91
+     * Assign variables
92
+     * @param string $key key
93
+     * @param array|bool|integer|string $value value
94
+     * @return bool
95
+     *
96
+     * This function assigns a variable. It can be accessed via $_[$key] in
97
+     * the template.
98
+     *
99
+     * If the key existed before, it will be overwritten
100
+     */
101
+    public function assign( $key, $value) {
102
+        $this->vars[$key] = $value;
103
+        return true;
104
+    }
105
+
106
+    /**
107
+     * Appends a variable
108
+     * @param string $key key
109
+     * @param mixed $value value
110
+     * @return boolean|null
111
+     *
112
+     * This function assigns a variable in an array context. If the key already
113
+     * exists, the value will be appended. It can be accessed via
114
+     * $_[$key][$position] in the template.
115
+     */
116
+    public function append( $key, $value ) {
117
+        if( array_key_exists( $key, $this->vars )) {
118
+            $this->vars[$key][] = $value;
119
+        }
120
+        else{
121
+            $this->vars[$key] = array( $value );
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Prints the proceeded template
127
+     * @return bool
128
+     *
129
+     * This function proceeds the template and prints its output.
130
+     */
131
+    public function printPage() {
132
+        $data = $this->fetchPage();
133
+        if( $data === false ) {
134
+            return false;
135
+        }
136
+        else{
137
+            print $data;
138
+            return true;
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Process the template
144
+     *
145
+     * @param array|null $additionalParams
146
+     * @return string This function processes the template.
147
+     *
148
+     * This function processes the template.
149
+     */
150
+    public function fetchPage($additionalParams = null) {
151
+        return $this->load($this->template, $additionalParams);
152
+    }
153
+
154
+    /**
155
+     * doing the actual work
156
+     *
157
+     * @param string $file
158
+     * @param array|null $additionalParams
159
+     * @return string content
160
+     *
161
+     * Includes the template file, fetches its output
162
+     */
163
+    protected function load($file, $additionalParams = null) {
164
+        // Register the variables
165
+        $_ = $this->vars;
166
+        $l = $this->l10n;
167
+        $theme = $this->theme;
168
+
169
+        if(!is_null($additionalParams)) {
170
+            $_ = array_merge( $additionalParams, $this->vars );
171
+            foreach ($_ as $var => $value) {
172
+                ${$var} = $value;
173
+            }
174
+        }
175
+
176
+        // Include
177
+        ob_start();
178
+        try {
179
+            include $file;
180
+            $data = ob_get_contents();
181
+        } catch (\Exception $e) {
182
+            @ob_end_clean();
183
+            throw $e;
184
+        }
185
+        @ob_end_clean();
186
+
187
+        // Return data
188
+        return $data;
189
+    }
190 190
 
191 191
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/TemplateResponse.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -37,124 +37,124 @@
 block discarded – undo
37 37
  */
38 38
 class TemplateResponse extends Response {
39 39
 
40
-	/**
41
-	 * name of the template
42
-	 * @var string
43
-	 */
44
-	protected $templateName;
45
-
46
-	/**
47
-	 * parameters
48
-	 * @var array
49
-	 */
50
-	protected $params;
51
-
52
-	/**
53
-	 * rendering type (admin, user, blank)
54
-	 * @var string
55
-	 */
56
-	protected $renderAs;
57
-
58
-	/**
59
-	 * app name
60
-	 * @var string
61
-	 */
62
-	protected $appName;
63
-
64
-	/**
65
-	 * constructor of TemplateResponse
66
-	 * @param string $appName the name of the app to load the template from
67
-	 * @param string $templateName the name of the template
68
-	 * @param array $params an array of parameters which should be passed to the
69
-	 * template
70
-	 * @param string $renderAs how the page should be rendered, defaults to user
71
-	 * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
72
-	 */
73
-	public function __construct($appName, $templateName, array $params=array(),
74
-	                            $renderAs='user') {
75
-		$this->templateName = $templateName;
76
-		$this->appName = $appName;
77
-		$this->params = $params;
78
-		$this->renderAs = $renderAs;
79
-	}
80
-
81
-
82
-	/**
83
-	 * Sets template parameters
84
-	 * @param array $params an array with key => value structure which sets template
85
-	 *                      variables
86
-	 * @return TemplateResponse Reference to this object
87
-	 * @since 6.0.0 - return value was added in 7.0.0
88
-	 */
89
-	public function setParams(array $params){
90
-		$this->params = $params;
91
-
92
-		return $this;
93
-	}
94
-
95
-
96
-	/**
97
-	 * Used for accessing the set parameters
98
-	 * @return array the params
99
-	 * @since 6.0.0
100
-	 */
101
-	public function getParams(){
102
-		return $this->params;
103
-	}
104
-
105
-
106
-	/**
107
-	 * Used for accessing the name of the set template
108
-	 * @return string the name of the used template
109
-	 * @since 6.0.0
110
-	 */
111
-	public function getTemplateName(){
112
-		return $this->templateName;
113
-	}
114
-
115
-
116
-	/**
117
-	 * Sets the template page
118
-	 * @param string $renderAs admin, user or blank. Admin also prints the admin
119
-	 *                         settings header and footer, user renders the normal
120
-	 *                         normal page including footer and header and blank
121
-	 *                         just renders the plain template
122
-	 * @return TemplateResponse Reference to this object
123
-	 * @since 6.0.0 - return value was added in 7.0.0
124
-	 */
125
-	public function renderAs($renderAs){
126
-		$this->renderAs = $renderAs;
127
-
128
-		return $this;
129
-	}
130
-
131
-
132
-	/**
133
-	 * Returns the set renderAs
134
-	 * @return string the renderAs value
135
-	 * @since 6.0.0
136
-	 */
137
-	public function getRenderAs(){
138
-		return $this->renderAs;
139
-	}
140
-
141
-
142
-	/**
143
-	 * Returns the rendered html
144
-	 * @return string the rendered html
145
-	 * @since 6.0.0
146
-	 */
147
-	public function render(){
148
-		// \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
149
-		$renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
150
-
151
-		$template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
152
-
153
-		foreach($this->params as $key => $value){
154
-			$template->assign($key, $value);
155
-		}
156
-
157
-		return $template->fetchPage($this->params);
158
-	}
40
+    /**
41
+     * name of the template
42
+     * @var string
43
+     */
44
+    protected $templateName;
45
+
46
+    /**
47
+     * parameters
48
+     * @var array
49
+     */
50
+    protected $params;
51
+
52
+    /**
53
+     * rendering type (admin, user, blank)
54
+     * @var string
55
+     */
56
+    protected $renderAs;
57
+
58
+    /**
59
+     * app name
60
+     * @var string
61
+     */
62
+    protected $appName;
63
+
64
+    /**
65
+     * constructor of TemplateResponse
66
+     * @param string $appName the name of the app to load the template from
67
+     * @param string $templateName the name of the template
68
+     * @param array $params an array of parameters which should be passed to the
69
+     * template
70
+     * @param string $renderAs how the page should be rendered, defaults to user
71
+     * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
72
+     */
73
+    public function __construct($appName, $templateName, array $params=array(),
74
+                                $renderAs='user') {
75
+        $this->templateName = $templateName;
76
+        $this->appName = $appName;
77
+        $this->params = $params;
78
+        $this->renderAs = $renderAs;
79
+    }
80
+
81
+
82
+    /**
83
+     * Sets template parameters
84
+     * @param array $params an array with key => value structure which sets template
85
+     *                      variables
86
+     * @return TemplateResponse Reference to this object
87
+     * @since 6.0.0 - return value was added in 7.0.0
88
+     */
89
+    public function setParams(array $params){
90
+        $this->params = $params;
91
+
92
+        return $this;
93
+    }
94
+
95
+
96
+    /**
97
+     * Used for accessing the set parameters
98
+     * @return array the params
99
+     * @since 6.0.0
100
+     */
101
+    public function getParams(){
102
+        return $this->params;
103
+    }
104
+
105
+
106
+    /**
107
+     * Used for accessing the name of the set template
108
+     * @return string the name of the used template
109
+     * @since 6.0.0
110
+     */
111
+    public function getTemplateName(){
112
+        return $this->templateName;
113
+    }
114
+
115
+
116
+    /**
117
+     * Sets the template page
118
+     * @param string $renderAs admin, user or blank. Admin also prints the admin
119
+     *                         settings header and footer, user renders the normal
120
+     *                         normal page including footer and header and blank
121
+     *                         just renders the plain template
122
+     * @return TemplateResponse Reference to this object
123
+     * @since 6.0.0 - return value was added in 7.0.0
124
+     */
125
+    public function renderAs($renderAs){
126
+        $this->renderAs = $renderAs;
127
+
128
+        return $this;
129
+    }
130
+
131
+
132
+    /**
133
+     * Returns the set renderAs
134
+     * @return string the renderAs value
135
+     * @since 6.0.0
136
+     */
137
+    public function getRenderAs(){
138
+        return $this->renderAs;
139
+    }
140
+
141
+
142
+    /**
143
+     * Returns the rendered html
144
+     * @return string the rendered html
145
+     * @since 6.0.0
146
+     */
147
+    public function render(){
148
+        // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
149
+        $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
150
+
151
+        $template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
152
+
153
+        foreach($this->params as $key => $value){
154
+            $template->assign($key, $value);
155
+        }
156
+
157
+        return $template->fetchPage($this->params);
158
+    }
159 159
 
160 160
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Template/IMenuAction.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -31,34 +31,34 @@
 block discarded – undo
31 31
  */
32 32
 interface IMenuAction {
33 33
 
34
-	/**
35
-	 * @since 14.0.0
36
-	 * @return string
37
-	 */
38
-	public function getId(): string;
34
+    /**
35
+     * @since 14.0.0
36
+     * @return string
37
+     */
38
+    public function getId(): string;
39 39
 
40
-	/**
41
-	 * @since 14.0.0
42
-	 * @return string
43
-	 */
44
-	public function getLabel(): string;
40
+    /**
41
+     * @since 14.0.0
42
+     * @return string
43
+     */
44
+    public function getLabel(): string;
45 45
 
46
-	/**
47
-	 * @since 14.0.0
48
-	 * @return string
49
-	 */
50
-	public function getLink(): string;
46
+    /**
47
+     * @since 14.0.0
48
+     * @return string
49
+     */
50
+    public function getLink(): string;
51 51
 
52
-	/**
53
-	 * @since 14.0.0
54
-	 * @return int
55
-	 */
56
-	public function getPriority(): int;
52
+    /**
53
+     * @since 14.0.0
54
+     * @return int
55
+     */
56
+    public function getPriority(): int;
57 57
 
58
-	/**
59
-	 * @since 14.0.0
60
-	 * @return string
61
-	 */
62
-	public function render(): string;
58
+    /**
59
+     * @since 14.0.0
60
+     * @return string
61
+     */
62
+    public function render(): string;
63 63
 
64 64
 }
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
core/templates/layout.public.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@  discard block
 block discarded – undo
4 4
 	<meta charset="utf-8">
5 5
 	<title>
6 6
 		<?php
7
-		p(!empty($_['application'])?$_['application'].' - ':'');
8
-		p($theme->getTitle());
9
-		?>
7
+        p(!empty($_['application'])?$_['application'].' - ':'');
8
+        p($theme->getTitle());
9
+        ?>
10 10
 	</title>
11 11
 	<meta http-equiv="X-UA-Compatible" content="IE=edge">
12 12
 	<meta name="referrer" content="never">
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 		</div>
43 43
 
44 44
 		<?php
45
-		/** @var \OCP\AppFramework\Http\Template\PublicTemplateResponse $template */
46
-		if($template->getActionCount() !== 0) {
47
-			$primary = $template->getPrimaryAction();
48
-			$others = $template->getOtherActions();
49
-			?>
45
+        /** @var \OCP\AppFramework\Http\Template\PublicTemplateResponse $template */
46
+        if($template->getActionCount() !== 0) {
47
+            $primary = $template->getPrimaryAction();
48
+            $others = $template->getOtherActions();
49
+            ?>
50 50
 		<div class="header-right">
51 51
 			<span id="header-primary-action" class="<?php if($template->getActionCount() === 1) {  p($primary->getIcon()); } ?>">
52 52
 				<a href="<?php p($primary->getLink()); ?>">
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
 			<div id="share-menu" class="popovermenu menu">
59 59
 				<ul>
60 60
 					<?php
61
-						/** @var \OCP\AppFramework\Http\Template\IMenuAction $action */
62
-						foreach($template->getOtherActions() as $action) {
63
-							print_unescaped($action->render());
64
-						}
65
-					?>
61
+                        /** @var \OCP\AppFramework\Http\Template\IMenuAction $action */
62
+                        foreach($template->getOtherActions() as $action) {
63
+                            print_unescaped($action->render());
64
+                        }
65
+                    ?>
66 66
 				</ul>
67 67
 			</div>
68 68
 			<?php } ?>
Please login to merge, or discard this patch.
apps/files_sharing/lib/Template/LinkMenuAction.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -28,27 +28,27 @@
 block discarded – undo
28 28
 
29 29
 class LinkMenuAction extends SimpleMenuAction {
30 30
 
31
-	/**
32
-	 * LinkMenuAction constructor.
33
-	 *
34
-	 * @param string $label
35
-	 * @param string $icon
36
-	 * @param string $link
37
-	 */
38
-	public function __construct(string $label, string $icon, string $link) {
39
-		parent::__construct('directLink-container', $label, $icon, $link);
40
-	}
31
+    /**
32
+     * LinkMenuAction constructor.
33
+     *
34
+     * @param string $label
35
+     * @param string $icon
36
+     * @param string $link
37
+     */
38
+    public function __construct(string $label, string $icon, string $link) {
39
+        parent::__construct('directLink-container', $label, $icon, $link);
40
+    }
41 41
 
42
-	/**
43
-	 * @return string
44
-	 */
45
-	public function render(): string {
46
-		return '<li>' .
47
-			'<a id="directLink-container">' .
48
-			'<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
49
-			'<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' .
50
-			'<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
51
-			'</a>' .
52
-			'</li>';
53
-	}
42
+    /**
43
+     * @return string
44
+     */
45
+    public function render(): string {
46
+        return '<li>' .
47
+            '<a id="directLink-container">' .
48
+            '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
49
+            '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' .
50
+            '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
51
+            '</a>' .
52
+            '</li>';
53
+    }
54 54
 }
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
apps/files_sharing/lib/Template/ExternalShareMenuAction.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -28,41 +28,41 @@
 block discarded – undo
28 28
 
29 29
 class ExternalShareMenuAction extends SimpleMenuAction {
30 30
 
31
-	/** @var string */
32
-	private $owner;
31
+    /** @var string */
32
+    private $owner;
33 33
 
34
-	/** @var string */
35
-	private $displayname;
34
+    /** @var string */
35
+    private $displayname;
36 36
 
37
-	/** @var string */
38
-	private $shareName;
37
+    /** @var string */
38
+    private $shareName;
39 39
 
40
-	/**
41
-	 * ExternalShareMenuAction constructor.
42
-	 *
43
-	 * @param string $label
44
-	 * @param string $icon
45
-	 * @param string $owner
46
-	 * @param string $displayname
47
-	 * @param string $shareName
48
-	 */
49
-	public function __construct(string $label, string $icon, string $owner, string $displayname, string $shareName) {
50
-		parent::__construct('save', $label, $icon);
51
-		$this->owner = $owner;
52
-		$this->displayname = $displayname;
53
-		$this->shareName = $shareName;
54
-	}
40
+    /**
41
+     * ExternalShareMenuAction constructor.
42
+     *
43
+     * @param string $label
44
+     * @param string $icon
45
+     * @param string $owner
46
+     * @param string $displayname
47
+     * @param string $shareName
48
+     */
49
+    public function __construct(string $label, string $icon, string $owner, string $displayname, string $shareName) {
50
+        parent::__construct('save', $label, $icon);
51
+        $this->owner = $owner;
52
+        $this->displayname = $displayname;
53
+        $this->shareName = $shareName;
54
+    }
55 55
 
56
-	public function render(): string {
57
-		return '<li>' .
58
-			'<a id="save" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' .
59
-			'<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
60
-			'<span id="save-button">' . Util::sanitizeHTML($this->getLabel()) . '</span>' .
61
-			'<form class="save-form hidden" action="#">' .
62
-			'<input type="text" id="remote_address" placeholder="[email protected]">' .
63
-			'<button id="save-button-confirm" class="icon-confirm svg" disabled=""></button>' .
64
-			'</form>' .
65
-			'</a>' .
66
-			'</li>';
67
-	}
56
+    public function render(): string {
57
+        return '<li>' .
58
+            '<a id="save" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' .
59
+            '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
60
+            '<span id="save-button">' . Util::sanitizeHTML($this->getLabel()) . '</span>' .
61
+            '<form class="save-form hidden" action="#">' .
62
+            '<input type="text" id="remote_address" placeholder="[email protected]">' .
63
+            '<button id="save-button-confirm" class="icon-confirm svg" disabled=""></button>' .
64
+            '</form>' .
65
+            '</a>' .
66
+            '</li>';
67
+    }
68 68
 }
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
lib/private/legacy/template.php 1 patch
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -46,349 +46,349 @@
 block discarded – undo
46 46
  */
47 47
 class OC_Template extends \OC\Template\Base {
48 48
 
49
-	/** @var string */
50
-	private $renderAs; // Create a full page?
51
-
52
-	/** @var string */
53
-	private $path; // The path to the template
54
-
55
-	/** @var array */
56
-	private $headers = array(); //custom headers
57
-
58
-	/** @var string */
59
-	protected $app; // app id
60
-
61
-	protected static $initTemplateEngineFirstRun = true;
62
-
63
-	/**
64
-	 * Constructor
65
-	 *
66
-	 * @param string $app app providing the template
67
-	 * @param string $name of the template file (without suffix)
68
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
69
-	 *                         produce a full page in the according layout. For
70
-	 *                         now, $renderAs can be set to "guest", "user" or
71
-	 *                         "admin".
72
-	 * @param bool $registerCall = true
73
-	 */
74
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
-		// Read the selected theme from the config file
76
-		self::initTemplateEngine($renderAs);
77
-
78
-		$theme = OC_Util::getTheme();
79
-
80
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
-
82
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
-		$l10n = \OC::$server->getL10N($parts[0]);
84
-		/** @var \OCP\Defaults $themeDefaults */
85
-		$themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
-
87
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
88
-
89
-		// Set the private data
90
-		$this->renderAs = $renderAs;
91
-		$this->path = $path;
92
-		$this->app = $app;
93
-
94
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
-	}
96
-
97
-	/**
98
-	 * @param string $renderAs
99
-	 */
100
-	public static function initTemplateEngine($renderAs) {
101
-		if (self::$initTemplateEngineFirstRun){
102
-
103
-			//apps that started before the template initialization can load their own scripts/styles
104
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
-			//meaning the last script/style in this list will be loaded first
106
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
-					OC_Util::addScript ( 'backgroundjobs', null, true );
109
-				}
110
-			}
111
-
112
-			OC_Util::addStyle('server', null, true);
113
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
114
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
115
-			OC_Util::addVendorStyle('select2/select2', null, true);
116
-			OC_Util::addStyle('jquery.ocdialog');
117
-			OC_Util::addTranslations("core", null, true);
118
-			OC_Util::addScript('search', 'search', true);
119
-			OC_Util::addScript('merged-template-prepend', null, true);
120
-			OC_Util::addScript('jquery-ui-fixes');
121
-			OC_Util::addScript('files/fileinfo');
122
-			OC_Util::addScript('files/client');
123
-			OC_Util::addScript('contactsmenu');
124
-
125
-			if (\OC::$server->getConfig()->getSystemValue('debug')) {
126
-				// Add the stuff we need always
127
-				// following logic will import all vendor libraries that are
128
-				// specified in core/js/core.json
129
-				$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
130
-				if($fileContent !== false) {
131
-					$coreDependencies = json_decode($fileContent, true);
132
-					foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
133
-						//remove trailing ".js" as addVendorScript will append it
134
-						OC_Util::addVendorScript(
135
-							substr($vendorLibrary, 0, -3),null,true);
136
-						}
137
- 				} else {
138
-					throw new \Exception('Cannot read core/js/core.json');
139
-				}
140
-			} else {
141
-				// Import all (combined) default vendor libraries
142
-				OC_Util::addVendorScript('core', null, true);
143
-			}
144
-
145
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
146
-				// polyfill for btoa/atob for IE friends
147
-				OC_Util::addVendorScript('base64/base64');
148
-				// shim for the davclient.js library
149
-				\OCP\Util::addScript('files/iedavclient');
150
-			}
151
-
152
-			self::$initTemplateEngineFirstRun = false;
153
-		}
154
-
155
-	}
156
-
157
-
158
-	/**
159
-	 * find the template with the given name
160
-	 * @param string $name of the template file (without suffix)
161
-	 *
162
-	 * Will select the template file for the selected theme.
163
-	 * Checking all the possible locations.
164
-	 * @param string $theme
165
-	 * @param string $app
166
-	 * @return string[]
167
-	 */
168
-	protected function findTemplate($theme, $app, $name) {
169
-		// Check if it is a app template or not.
170
-		if( $app !== '' ) {
171
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
172
-		} else {
173
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
174
-		}
175
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
176
-		$template = $locator->find($name);
177
-		$path = $locator->getPath();
178
-		return array($path, $template);
179
-	}
180
-
181
-	/**
182
-	 * Add a custom element to the header
183
-	 * @param string $tag tag name of the element
184
-	 * @param array $attributes array of attributes for the element
185
-	 * @param string $text the text content for the element. If $text is null then the
186
-	 * element will be written as empty element. So use "" to get a closing tag.
187
-	 */
188
-	public function addHeader($tag, $attributes, $text=null) {
189
-		$this->headers[]= array(
190
-			'tag' => $tag,
191
-			'attributes' => $attributes,
192
-			'text' => $text
193
-		);
194
-	}
195
-
196
-	/**
197
-	 * Process the template
198
-	 * @return boolean|string
199
-	 *
200
-	 * This function process the template. If $this->renderAs is set, it
201
-	 * will produce a full page.
202
-	 */
203
-	public function fetchPage($additionalParams = null) {
204
-		$data = parent::fetchPage($additionalParams);
205
-
206
-		if( $this->renderAs ) {
207
-			$page = new TemplateLayout($this->renderAs, $this->app);
208
-
209
-			if(is_array($additionalParams)) {
210
-				foreach ($additionalParams as $key => $value) {
211
-					$page->assign($key, $value);
212
-				}
213
-			}
214
-
215
-			// Add custom headers
216
-			$headers = '';
217
-			foreach(OC_Util::$headers as $header) {
218
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
219
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
220
-					$headers .= ' defer';
221
-				}
222
-				foreach($header['attributes'] as $name=>$value) {
223
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
224
-				}
225
-				if ($header['text'] !== null) {
226
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
227
-				} else {
228
-					$headers .= '/>';
229
-				}
230
-			}
231
-
232
-			$page->assign('headers', $headers);
233
-
234
-			$page->assign('content', $data);
235
-			return $page->fetchPage($additionalParams);
236
-		}
237
-
238
-		return $data;
239
-	}
240
-
241
-	/**
242
-	 * Include template
243
-	 *
244
-	 * @param string $file
245
-	 * @param array|null $additionalParams
246
-	 * @return string returns content of included template
247
-	 *
248
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
249
-	 * do this.
250
-	 */
251
-	public function inc( $file, $additionalParams = null ) {
252
-		return $this->load($this->path.$file.'.php', $additionalParams);
253
-	}
254
-
255
-	/**
256
-	 * Shortcut to print a simple page for users
257
-	 * @param string $application The application we render the template for
258
-	 * @param string $name Name of the template
259
-	 * @param array $parameters Parameters for the template
260
-	 * @return boolean|null
261
-	 */
262
-	public static function printUserPage( $application, $name, $parameters = array() ) {
263
-		$content = new OC_Template( $application, $name, "user" );
264
-		foreach( $parameters as $key => $value ) {
265
-			$content->assign( $key, $value );
266
-		}
267
-		print $content->printPage();
268
-	}
269
-
270
-	/**
271
-	 * Shortcut to print a simple page for admins
272
-	 * @param string $application The application we render the template for
273
-	 * @param string $name Name of the template
274
-	 * @param array $parameters Parameters for the template
275
-	 * @return bool
276
-	 */
277
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
278
-		$content = new OC_Template( $application, $name, "admin" );
279
-		foreach( $parameters as $key => $value ) {
280
-			$content->assign( $key, $value );
281
-		}
282
-		return $content->printPage();
283
-	}
284
-
285
-	/**
286
-	 * Shortcut to print a simple page for guests
287
-	 * @param string $application The application we render the template for
288
-	 * @param string $name Name of the template
289
-	 * @param array|string $parameters Parameters for the template
290
-	 * @return bool
291
-	 */
292
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
293
-		$content = new OC_Template( $application, $name, "guest" );
294
-		foreach( $parameters as $key => $value ) {
295
-			$content->assign( $key, $value );
296
-		}
297
-		return $content->printPage();
298
-	}
299
-
300
-	/**
301
-	 * Print a fatal error page and terminates the script
302
-	 * @param string $error_msg The error message to show
303
-	 * @param string $hint An optional hint message - needs to be properly escape
304
-	 * @suppress PhanAccessMethodInternal
305
-	 */
306
-	public static function printErrorPage( $error_msg, $hint = '' ) {
307
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
308
-			\OC_App::loadApp('theming');
309
-		}
310
-
311
-
312
-		if ($error_msg === $hint) {
313
-			// If the hint is the same as the message there is no need to display it twice.
314
-			$hint = '';
315
-		}
316
-
317
-		try {
318
-			$content = new \OC_Template( '', 'error', 'error', false );
319
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
320
-			$content->assign( 'errors', $errors );
321
-			$content->printPage();
322
-		} catch (\Exception $e) {
323
-			$logger = \OC::$server->getLogger();
324
-			$logger->error("$error_msg $hint", ['app' => 'core']);
325
-			$logger->logException($e, ['app' => 'core']);
326
-
327
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
328
-			header('Content-Type: text/plain; charset=utf-8');
329
-			print("$error_msg $hint");
330
-		}
331
-		die();
332
-	}
333
-
334
-	/**
335
-	 * print error page using Exception details
336
-	 * @param Exception|Throwable $exception
337
-	 * @param bool $fetchPage
338
-	 * @return bool|string
339
-	 * @suppress PhanAccessMethodInternal
340
-	 */
341
-	public static function printExceptionErrorPage($exception, $fetchPage = false) {
342
-		try {
343
-			$request = \OC::$server->getRequest();
344
-			$content = new \OC_Template('', 'exception', 'error', false);
345
-			$content->assign('errorClass', get_class($exception));
346
-			$content->assign('errorMsg', $exception->getMessage());
347
-			$content->assign('errorCode', $exception->getCode());
348
-			$content->assign('file', $exception->getFile());
349
-			$content->assign('line', $exception->getLine());
350
-			$content->assign('trace', $exception->getTraceAsString());
351
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
352
-			$content->assign('remoteAddr', $request->getRemoteAddress());
353
-			$content->assign('requestID', $request->getId());
354
-			if ($fetchPage) {
355
-				return $content->fetchPage();
356
-			}
357
-			$content->printPage();
358
-		} catch (\Exception $e) {
359
-			$logger = \OC::$server->getLogger();
360
-			$logger->logException($exception, ['app' => 'core']);
361
-			$logger->logException($e, ['app' => 'core']);
362
-
363
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
364
-			header('Content-Type: text/plain; charset=utf-8');
365
-			print("Internal Server Error\n\n");
366
-			print("The server encountered an internal error and was unable to complete your request.\n");
367
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
368
-			print("More details can be found in the server log.\n");
369
-		}
370
-		die();
371
-	}
372
-
373
-	/**
374
-	 * This is only here to reduce the dependencies in case of an exception to
375
-	 * still be able to print a plain error message.
376
-	 *
377
-	 * Returns the used HTTP protocol.
378
-	 *
379
-	 * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
380
-	 * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
381
-	 */
382
-	protected static function getHttpProtocol() {
383
-		$claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
384
-		$validProtocols = [
385
-			'HTTP/1.0',
386
-			'HTTP/1.1',
387
-			'HTTP/2',
388
-		];
389
-		if(in_array($claimedProtocol, $validProtocols, true)) {
390
-			return $claimedProtocol;
391
-		}
392
-		return 'HTTP/1.1';
393
-	}
49
+    /** @var string */
50
+    private $renderAs; // Create a full page?
51
+
52
+    /** @var string */
53
+    private $path; // The path to the template
54
+
55
+    /** @var array */
56
+    private $headers = array(); //custom headers
57
+
58
+    /** @var string */
59
+    protected $app; // app id
60
+
61
+    protected static $initTemplateEngineFirstRun = true;
62
+
63
+    /**
64
+     * Constructor
65
+     *
66
+     * @param string $app app providing the template
67
+     * @param string $name of the template file (without suffix)
68
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
69
+     *                         produce a full page in the according layout. For
70
+     *                         now, $renderAs can be set to "guest", "user" or
71
+     *                         "admin".
72
+     * @param bool $registerCall = true
73
+     */
74
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
+        // Read the selected theme from the config file
76
+        self::initTemplateEngine($renderAs);
77
+
78
+        $theme = OC_Util::getTheme();
79
+
80
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
81
+
82
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
83
+        $l10n = \OC::$server->getL10N($parts[0]);
84
+        /** @var \OCP\Defaults $themeDefaults */
85
+        $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
86
+
87
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
88
+
89
+        // Set the private data
90
+        $this->renderAs = $renderAs;
91
+        $this->path = $path;
92
+        $this->app = $app;
93
+
94
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
95
+    }
96
+
97
+    /**
98
+     * @param string $renderAs
99
+     */
100
+    public static function initTemplateEngine($renderAs) {
101
+        if (self::$initTemplateEngineFirstRun){
102
+
103
+            //apps that started before the template initialization can load their own scripts/styles
104
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105
+            //meaning the last script/style in this list will be loaded first
106
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
107
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
108
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
109
+                }
110
+            }
111
+
112
+            OC_Util::addStyle('server', null, true);
113
+            OC_Util::addStyle('jquery-ui-fixes',null,true);
114
+            OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
115
+            OC_Util::addVendorStyle('select2/select2', null, true);
116
+            OC_Util::addStyle('jquery.ocdialog');
117
+            OC_Util::addTranslations("core", null, true);
118
+            OC_Util::addScript('search', 'search', true);
119
+            OC_Util::addScript('merged-template-prepend', null, true);
120
+            OC_Util::addScript('jquery-ui-fixes');
121
+            OC_Util::addScript('files/fileinfo');
122
+            OC_Util::addScript('files/client');
123
+            OC_Util::addScript('contactsmenu');
124
+
125
+            if (\OC::$server->getConfig()->getSystemValue('debug')) {
126
+                // Add the stuff we need always
127
+                // following logic will import all vendor libraries that are
128
+                // specified in core/js/core.json
129
+                $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
130
+                if($fileContent !== false) {
131
+                    $coreDependencies = json_decode($fileContent, true);
132
+                    foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
133
+                        //remove trailing ".js" as addVendorScript will append it
134
+                        OC_Util::addVendorScript(
135
+                            substr($vendorLibrary, 0, -3),null,true);
136
+                        }
137
+                    } else {
138
+                    throw new \Exception('Cannot read core/js/core.json');
139
+                }
140
+            } else {
141
+                // Import all (combined) default vendor libraries
142
+                OC_Util::addVendorScript('core', null, true);
143
+            }
144
+
145
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
146
+                // polyfill for btoa/atob for IE friends
147
+                OC_Util::addVendorScript('base64/base64');
148
+                // shim for the davclient.js library
149
+                \OCP\Util::addScript('files/iedavclient');
150
+            }
151
+
152
+            self::$initTemplateEngineFirstRun = false;
153
+        }
154
+
155
+    }
156
+
157
+
158
+    /**
159
+     * find the template with the given name
160
+     * @param string $name of the template file (without suffix)
161
+     *
162
+     * Will select the template file for the selected theme.
163
+     * Checking all the possible locations.
164
+     * @param string $theme
165
+     * @param string $app
166
+     * @return string[]
167
+     */
168
+    protected function findTemplate($theme, $app, $name) {
169
+        // Check if it is a app template or not.
170
+        if( $app !== '' ) {
171
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
172
+        } else {
173
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
174
+        }
175
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
176
+        $template = $locator->find($name);
177
+        $path = $locator->getPath();
178
+        return array($path, $template);
179
+    }
180
+
181
+    /**
182
+     * Add a custom element to the header
183
+     * @param string $tag tag name of the element
184
+     * @param array $attributes array of attributes for the element
185
+     * @param string $text the text content for the element. If $text is null then the
186
+     * element will be written as empty element. So use "" to get a closing tag.
187
+     */
188
+    public function addHeader($tag, $attributes, $text=null) {
189
+        $this->headers[]= array(
190
+            'tag' => $tag,
191
+            'attributes' => $attributes,
192
+            'text' => $text
193
+        );
194
+    }
195
+
196
+    /**
197
+     * Process the template
198
+     * @return boolean|string
199
+     *
200
+     * This function process the template. If $this->renderAs is set, it
201
+     * will produce a full page.
202
+     */
203
+    public function fetchPage($additionalParams = null) {
204
+        $data = parent::fetchPage($additionalParams);
205
+
206
+        if( $this->renderAs ) {
207
+            $page = new TemplateLayout($this->renderAs, $this->app);
208
+
209
+            if(is_array($additionalParams)) {
210
+                foreach ($additionalParams as $key => $value) {
211
+                    $page->assign($key, $value);
212
+                }
213
+            }
214
+
215
+            // Add custom headers
216
+            $headers = '';
217
+            foreach(OC_Util::$headers as $header) {
218
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
219
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
220
+                    $headers .= ' defer';
221
+                }
222
+                foreach($header['attributes'] as $name=>$value) {
223
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
224
+                }
225
+                if ($header['text'] !== null) {
226
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
227
+                } else {
228
+                    $headers .= '/>';
229
+                }
230
+            }
231
+
232
+            $page->assign('headers', $headers);
233
+
234
+            $page->assign('content', $data);
235
+            return $page->fetchPage($additionalParams);
236
+        }
237
+
238
+        return $data;
239
+    }
240
+
241
+    /**
242
+     * Include template
243
+     *
244
+     * @param string $file
245
+     * @param array|null $additionalParams
246
+     * @return string returns content of included template
247
+     *
248
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
249
+     * do this.
250
+     */
251
+    public function inc( $file, $additionalParams = null ) {
252
+        return $this->load($this->path.$file.'.php', $additionalParams);
253
+    }
254
+
255
+    /**
256
+     * Shortcut to print a simple page for users
257
+     * @param string $application The application we render the template for
258
+     * @param string $name Name of the template
259
+     * @param array $parameters Parameters for the template
260
+     * @return boolean|null
261
+     */
262
+    public static function printUserPage( $application, $name, $parameters = array() ) {
263
+        $content = new OC_Template( $application, $name, "user" );
264
+        foreach( $parameters as $key => $value ) {
265
+            $content->assign( $key, $value );
266
+        }
267
+        print $content->printPage();
268
+    }
269
+
270
+    /**
271
+     * Shortcut to print a simple page for admins
272
+     * @param string $application The application we render the template for
273
+     * @param string $name Name of the template
274
+     * @param array $parameters Parameters for the template
275
+     * @return bool
276
+     */
277
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
278
+        $content = new OC_Template( $application, $name, "admin" );
279
+        foreach( $parameters as $key => $value ) {
280
+            $content->assign( $key, $value );
281
+        }
282
+        return $content->printPage();
283
+    }
284
+
285
+    /**
286
+     * Shortcut to print a simple page for guests
287
+     * @param string $application The application we render the template for
288
+     * @param string $name Name of the template
289
+     * @param array|string $parameters Parameters for the template
290
+     * @return bool
291
+     */
292
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
293
+        $content = new OC_Template( $application, $name, "guest" );
294
+        foreach( $parameters as $key => $value ) {
295
+            $content->assign( $key, $value );
296
+        }
297
+        return $content->printPage();
298
+    }
299
+
300
+    /**
301
+     * Print a fatal error page and terminates the script
302
+     * @param string $error_msg The error message to show
303
+     * @param string $hint An optional hint message - needs to be properly escape
304
+     * @suppress PhanAccessMethodInternal
305
+     */
306
+    public static function printErrorPage( $error_msg, $hint = '' ) {
307
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
308
+            \OC_App::loadApp('theming');
309
+        }
310
+
311
+
312
+        if ($error_msg === $hint) {
313
+            // If the hint is the same as the message there is no need to display it twice.
314
+            $hint = '';
315
+        }
316
+
317
+        try {
318
+            $content = new \OC_Template( '', 'error', 'error', false );
319
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
320
+            $content->assign( 'errors', $errors );
321
+            $content->printPage();
322
+        } catch (\Exception $e) {
323
+            $logger = \OC::$server->getLogger();
324
+            $logger->error("$error_msg $hint", ['app' => 'core']);
325
+            $logger->logException($e, ['app' => 'core']);
326
+
327
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
328
+            header('Content-Type: text/plain; charset=utf-8');
329
+            print("$error_msg $hint");
330
+        }
331
+        die();
332
+    }
333
+
334
+    /**
335
+     * print error page using Exception details
336
+     * @param Exception|Throwable $exception
337
+     * @param bool $fetchPage
338
+     * @return bool|string
339
+     * @suppress PhanAccessMethodInternal
340
+     */
341
+    public static function printExceptionErrorPage($exception, $fetchPage = false) {
342
+        try {
343
+            $request = \OC::$server->getRequest();
344
+            $content = new \OC_Template('', 'exception', 'error', false);
345
+            $content->assign('errorClass', get_class($exception));
346
+            $content->assign('errorMsg', $exception->getMessage());
347
+            $content->assign('errorCode', $exception->getCode());
348
+            $content->assign('file', $exception->getFile());
349
+            $content->assign('line', $exception->getLine());
350
+            $content->assign('trace', $exception->getTraceAsString());
351
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
352
+            $content->assign('remoteAddr', $request->getRemoteAddress());
353
+            $content->assign('requestID', $request->getId());
354
+            if ($fetchPage) {
355
+                return $content->fetchPage();
356
+            }
357
+            $content->printPage();
358
+        } catch (\Exception $e) {
359
+            $logger = \OC::$server->getLogger();
360
+            $logger->logException($exception, ['app' => 'core']);
361
+            $logger->logException($e, ['app' => 'core']);
362
+
363
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
364
+            header('Content-Type: text/plain; charset=utf-8');
365
+            print("Internal Server Error\n\n");
366
+            print("The server encountered an internal error and was unable to complete your request.\n");
367
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
368
+            print("More details can be found in the server log.\n");
369
+        }
370
+        die();
371
+    }
372
+
373
+    /**
374
+     * This is only here to reduce the dependencies in case of an exception to
375
+     * still be able to print a plain error message.
376
+     *
377
+     * Returns the used HTTP protocol.
378
+     *
379
+     * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
380
+     * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
381
+     */
382
+    protected static function getHttpProtocol() {
383
+        $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
384
+        $validProtocols = [
385
+            'HTTP/1.0',
386
+            'HTTP/1.1',
387
+            'HTTP/2',
388
+        ];
389
+        if(in_array($claimedProtocol, $validProtocols, true)) {
390
+            return $claimedProtocol;
391
+        }
392
+        return 'HTTP/1.1';
393
+    }
394 394
 }
Please login to merge, or discard this patch.
lib/private/TemplateLayout.php 1 patch
Indentation   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -45,290 +45,290 @@
 block discarded – undo
45 45
 
46 46
 class TemplateLayout extends \OC_Template {
47 47
 
48
-	private static $versionHash = '';
49
-
50
-	/**
51
-	 * @var \OCP\IConfig
52
-	 */
53
-	private $config;
54
-
55
-	/**
56
-	 * @param string $renderAs
57
-	 * @param string $appId application id
58
-	 */
59
-	public function __construct( $renderAs, $appId = '' ) {
60
-
61
-		// yes - should be injected ....
62
-		$this->config = \OC::$server->getConfig();
63
-
64
-
65
-		// Decide which page we show
66
-		if($renderAs == 'user') {
67
-			parent::__construct( 'core', 'layout.user' );
68
-			if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
-				$this->assign('bodyid', 'body-settings');
70
-			}else{
71
-				$this->assign('bodyid', 'body-user');
72
-			}
73
-
74
-			// Code integrity notification
75
-			$integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
-			if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
-				\OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
-			}
79
-
80
-			// Add navigation entry
81
-			$this->assign( 'application', '');
82
-			$this->assign( 'appid', $appId );
83
-			$navigation = \OC_App::getNavigation();
84
-			$this->assign( 'navigation', $navigation);
85
-			$settingsNavigation = \OC_App::getSettingsNavigation();
86
-			$this->assign( 'settingsnavigation', $settingsNavigation);
87
-			foreach($navigation as $entry) {
88
-				if ($entry['active']) {
89
-					$this->assign( 'application', $entry['name'] );
90
-					break;
91
-				}
92
-			}
93
-
94
-			foreach($settingsNavigation as $entry) {
95
-				if ($entry['active']) {
96
-					$this->assign( 'application', $entry['name'] );
97
-					break;
98
-				}
99
-			}
100
-			$userDisplayName = \OC_User::getDisplayName();
101
-			$this->assign('user_displayname', $userDisplayName);
102
-			$this->assign('user_uid', \OC_User::getUser());
103
-
104
-			if (\OC_User::getUser() === false) {
105
-				$this->assign('userAvatarSet', false);
106
-			} else {
107
-				$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
-				$this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
-			}
110
-
111
-			// check if app menu icons should be inverted
112
-			try {
113
-				/** @var \OCA\Theming\Util $util */
114
-				$util = \OC::$server->query(\OCA\Theming\Util::class);
115
-				$this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
-			} catch (\OCP\AppFramework\QueryException $e) {
117
-				$this->assign('themingInvertMenu', false);
118
-			}
119
-
120
-		} else if ($renderAs == 'error') {
121
-			parent::__construct('core', 'layout.guest', '', false);
122
-			$this->assign('bodyid', 'body-login');
123
-		} else if ($renderAs == 'guest') {
124
-			parent::__construct('core', 'layout.guest');
125
-			$this->assign('bodyid', 'body-login');
126
-		} else if ($renderAs == 'public') {
127
-			parent::__construct('core', 'layout.public');
128
-			$this->assign( 'appid', $appId );
129
-			$this->assign('bodyid', 'body-public');
130
-		} else {
131
-			parent::__construct('core', 'layout.base');
132
-
133
-		}
134
-		// Send the language to our layouts
135
-		$lang = \OC::$server->getL10NFactory()->findLanguage();
136
-		$lang = str_replace('_', '-', $lang);
137
-		$this->assign('language', $lang);
138
-
139
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
140
-			if (empty(self::$versionHash)) {
141
-				$v = \OC_App::getAppVersions();
142
-				$v['core'] = implode('.', \OCP\Util::getVersion());
143
-				self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
144
-			}
145
-		} else {
146
-			self::$versionHash = md5('not installed');
147
-		}
148
-
149
-		// Add the js files
150
-		$jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
151
-		$this->assign('jsfiles', array());
152
-		if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
153
-			if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
154
-				$jsConfigHelper = new JSConfigHelper(
155
-					\OC::$server->getL10N('lib'),
156
-					\OC::$server->query(Defaults::class),
157
-					\OC::$server->getAppManager(),
158
-					\OC::$server->getSession(),
159
-					\OC::$server->getUserSession()->getUser(),
160
-					$this->config,
161
-					\OC::$server->getGroupManager(),
162
-					\OC::$server->getIniWrapper(),
163
-					\OC::$server->getURLGenerator()
164
-				);
165
-				$this->assign('inline_ocjs', $jsConfigHelper->getConfig());
166
-			} else {
167
-				$this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
168
-			}
169
-		}
170
-		foreach($jsFiles as $info) {
171
-			$web = $info[1];
172
-			$file = $info[2];
173
-			$this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
174
-		}
175
-
176
-		try {
177
-			$pathInfo = \OC::$server->getRequest()->getPathInfo();
178
-		} catch (\Exception $e) {
179
-			$pathInfo = '';
180
-		}
181
-
182
-		// Do not initialise scss appdata until we have a fully installed instance
183
-		// Do not load scss for update, errors, installation or login page
184
-		if(\OC::$server->getSystemConfig()->getValue('installed', false)
185
-			&& !\OCP\Util::needUpgrade()
186
-			&& $pathInfo !== ''
187
-			&& !preg_match('/^\/login/', $pathInfo)
188
-			&& $renderAs !== 'error' && $renderAs !== 'guest'
189
-		) {
190
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
191
-		} else {
192
-			// If we ignore the scss compiler,
193
-			// we need to load the guest css fallback
194
-			\OC_Util::addStyle('guest');
195
-			$cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
196
-		}
197
-
198
-		$this->assign('cssfiles', array());
199
-		$this->assign('printcssfiles', []);
200
-		$this->assign('versionHash', self::$versionHash);
201
-		foreach($cssFiles as $info) {
202
-			$web = $info[1];
203
-			$file = $info[2];
204
-
205
-			if (substr($file, -strlen('print.css')) === 'print.css') {
206
-				$this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
207
-			} else {
208
-				$this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
209
-			}
210
-		}
211
-	}
212
-
213
-	/**
214
-	 * @param string $path
215
- 	 * @param string $file
216
-	 * @return string
217
-	 */
218
-	protected function getVersionHashSuffix($path = false, $file = false) {
219
-		if ($this->config->getSystemValue('debug', false)) {
220
-			// allows chrome workspace mapping in debug mode
221
-			return "";
222
-		}
223
-		$themingSuffix = '';
224
-		$v = [];
225
-
226
-		if ($this->config->getSystemValue('installed', false)) {
227
-			if (\OC::$server->getAppManager()->isInstalled('theming')) {
228
-				$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
229
-			}
230
-			$v = \OC_App::getAppVersions();
231
-		}
232
-
233
-		// Try the webroot path for a match
234
-		if ($path !== false && $path !== '') {
235
-			$appName = $this->getAppNamefromPath($path);
236
-			if(array_key_exists($appName, $v)) {
237
-				$appVersion = $v[$appName];
238
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
239
-			}
240
-		}
241
-		// fallback to the file path instead
242
-		if ($file !== false && $file !== '') {
243
-			$appName = $this->getAppNamefromPath($file);
244
-			if(array_key_exists($appName, $v)) {
245
-				$appVersion = $v[$appName];
246
-				return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
247
-			}
248
-		}
249
-
250
-		return '?v=' . self::$versionHash . $themingSuffix;
251
-	}
252
-
253
-	/**
254
-	 * @param array $styles
255
-	 * @return array
256
-	 */
257
-	static public function findStylesheetFiles($styles, $compileScss = true) {
258
-		// Read the selected theme from the config file
259
-		$theme = \OC_Util::getTheme();
260
-
261
-		if($compileScss) {
262
-			$SCSSCacher = \OC::$server->query(SCSSCacher::class);
263
-		} else {
264
-			$SCSSCacher = null;
265
-		}
266
-
267
-		$locator = new \OC\Template\CSSResourceLocator(
268
-			\OC::$server->getLogger(),
269
-			$theme,
270
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
271
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
272
-			$SCSSCacher
273
-		);
274
-		$locator->find($styles);
275
-		return $locator->getResources();
276
-	}
277
-
278
-	/**
279
-	 * @param string $path
280
-	 * @return string|boolean
281
-	 */
282
-	public function getAppNamefromPath($path) {
283
-		if ($path !== '' && is_string($path)) {
284
-			$pathParts = explode('/', $path);
285
-			if ($pathParts[0] === 'css') {
286
-				// This is a scss request
287
-				return $pathParts[1];
288
-			}
289
-			return end($pathParts);
290
-		}
291
-		return false;
292
-
293
-	}
294
-
295
-	/**
296
-	 * @param array $scripts
297
-	 * @return array
298
-	 */
299
-	static public function findJavascriptFiles($scripts) {
300
-		// Read the selected theme from the config file
301
-		$theme = \OC_Util::getTheme();
302
-
303
-		$locator = new \OC\Template\JSResourceLocator(
304
-			\OC::$server->getLogger(),
305
-			$theme,
306
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
307
-			array( \OC::$SERVERROOT => \OC::$WEBROOT ),
308
-			new JSCombiner(
309
-				\OC::$server->getAppDataDir('js'),
310
-				\OC::$server->getURLGenerator(),
311
-				\OC::$server->getMemCacheFactory()->createDistributed('JS'),
312
-				\OC::$server->getSystemConfig(),
313
-				\OC::$server->getLogger()
314
-			)
315
-			);
316
-		$locator->find($scripts);
317
-		return $locator->getResources();
318
-	}
319
-
320
-	/**
321
-	 * Converts the absolute file path to a relative path from \OC::$SERVERROOT
322
-	 * @param string $filePath Absolute path
323
-	 * @return string Relative path
324
-	 * @throws \Exception If $filePath is not under \OC::$SERVERROOT
325
-	 */
326
-	public static function convertToRelativePath($filePath) {
327
-		$relativePath = explode(\OC::$SERVERROOT, $filePath);
328
-		if(count($relativePath) !== 2) {
329
-			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
330
-		}
331
-
332
-		return $relativePath[1];
333
-	}
48
+    private static $versionHash = '';
49
+
50
+    /**
51
+     * @var \OCP\IConfig
52
+     */
53
+    private $config;
54
+
55
+    /**
56
+     * @param string $renderAs
57
+     * @param string $appId application id
58
+     */
59
+    public function __construct( $renderAs, $appId = '' ) {
60
+
61
+        // yes - should be injected ....
62
+        $this->config = \OC::$server->getConfig();
63
+
64
+
65
+        // Decide which page we show
66
+        if($renderAs == 'user') {
67
+            parent::__construct( 'core', 'layout.user' );
68
+            if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) {
69
+                $this->assign('bodyid', 'body-settings');
70
+            }else{
71
+                $this->assign('bodyid', 'body-user');
72
+            }
73
+
74
+            // Code integrity notification
75
+            $integrityChecker = \OC::$server->getIntegrityCodeChecker();
76
+            if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) {
77
+                \OCP\Util::addScript('core', 'integritycheck-failed-notification');
78
+            }
79
+
80
+            // Add navigation entry
81
+            $this->assign( 'application', '');
82
+            $this->assign( 'appid', $appId );
83
+            $navigation = \OC_App::getNavigation();
84
+            $this->assign( 'navigation', $navigation);
85
+            $settingsNavigation = \OC_App::getSettingsNavigation();
86
+            $this->assign( 'settingsnavigation', $settingsNavigation);
87
+            foreach($navigation as $entry) {
88
+                if ($entry['active']) {
89
+                    $this->assign( 'application', $entry['name'] );
90
+                    break;
91
+                }
92
+            }
93
+
94
+            foreach($settingsNavigation as $entry) {
95
+                if ($entry['active']) {
96
+                    $this->assign( 'application', $entry['name'] );
97
+                    break;
98
+                }
99
+            }
100
+            $userDisplayName = \OC_User::getDisplayName();
101
+            $this->assign('user_displayname', $userDisplayName);
102
+            $this->assign('user_uid', \OC_User::getUser());
103
+
104
+            if (\OC_User::getUser() === false) {
105
+                $this->assign('userAvatarSet', false);
106
+            } else {
107
+                $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
108
+                $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
109
+            }
110
+
111
+            // check if app menu icons should be inverted
112
+            try {
113
+                /** @var \OCA\Theming\Util $util */
114
+                $util = \OC::$server->query(\OCA\Theming\Util::class);
115
+                $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary()));
116
+            } catch (\OCP\AppFramework\QueryException $e) {
117
+                $this->assign('themingInvertMenu', false);
118
+            }
119
+
120
+        } else if ($renderAs == 'error') {
121
+            parent::__construct('core', 'layout.guest', '', false);
122
+            $this->assign('bodyid', 'body-login');
123
+        } else if ($renderAs == 'guest') {
124
+            parent::__construct('core', 'layout.guest');
125
+            $this->assign('bodyid', 'body-login');
126
+        } else if ($renderAs == 'public') {
127
+            parent::__construct('core', 'layout.public');
128
+            $this->assign( 'appid', $appId );
129
+            $this->assign('bodyid', 'body-public');
130
+        } else {
131
+            parent::__construct('core', 'layout.base');
132
+
133
+        }
134
+        // Send the language to our layouts
135
+        $lang = \OC::$server->getL10NFactory()->findLanguage();
136
+        $lang = str_replace('_', '-', $lang);
137
+        $this->assign('language', $lang);
138
+
139
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
140
+            if (empty(self::$versionHash)) {
141
+                $v = \OC_App::getAppVersions();
142
+                $v['core'] = implode('.', \OCP\Util::getVersion());
143
+                self::$versionHash = substr(md5(implode(',', $v)), 0, 8);
144
+            }
145
+        } else {
146
+            self::$versionHash = md5('not installed');
147
+        }
148
+
149
+        // Add the js files
150
+        $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts);
151
+        $this->assign('jsfiles', array());
152
+        if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') {
153
+            if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
154
+                $jsConfigHelper = new JSConfigHelper(
155
+                    \OC::$server->getL10N('lib'),
156
+                    \OC::$server->query(Defaults::class),
157
+                    \OC::$server->getAppManager(),
158
+                    \OC::$server->getSession(),
159
+                    \OC::$server->getUserSession()->getUser(),
160
+                    $this->config,
161
+                    \OC::$server->getGroupManager(),
162
+                    \OC::$server->getIniWrapper(),
163
+                    \OC::$server->getURLGenerator()
164
+                );
165
+                $this->assign('inline_ocjs', $jsConfigHelper->getConfig());
166
+            } else {
167
+                $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash]));
168
+            }
169
+        }
170
+        foreach($jsFiles as $info) {
171
+            $web = $info[1];
172
+            $file = $info[2];
173
+            $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
174
+        }
175
+
176
+        try {
177
+            $pathInfo = \OC::$server->getRequest()->getPathInfo();
178
+        } catch (\Exception $e) {
179
+            $pathInfo = '';
180
+        }
181
+
182
+        // Do not initialise scss appdata until we have a fully installed instance
183
+        // Do not load scss for update, errors, installation or login page
184
+        if(\OC::$server->getSystemConfig()->getValue('installed', false)
185
+            && !\OCP\Util::needUpgrade()
186
+            && $pathInfo !== ''
187
+            && !preg_match('/^\/login/', $pathInfo)
188
+            && $renderAs !== 'error' && $renderAs !== 'guest'
189
+        ) {
190
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles);
191
+        } else {
192
+            // If we ignore the scss compiler,
193
+            // we need to load the guest css fallback
194
+            \OC_Util::addStyle('guest');
195
+            $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false);
196
+        }
197
+
198
+        $this->assign('cssfiles', array());
199
+        $this->assign('printcssfiles', []);
200
+        $this->assign('versionHash', self::$versionHash);
201
+        foreach($cssFiles as $info) {
202
+            $web = $info[1];
203
+            $file = $info[2];
204
+
205
+            if (substr($file, -strlen('print.css')) === 'print.css') {
206
+                $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() );
207
+            } else {
208
+                $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file)  );
209
+            }
210
+        }
211
+    }
212
+
213
+    /**
214
+     * @param string $path
215
+     * @param string $file
216
+     * @return string
217
+     */
218
+    protected function getVersionHashSuffix($path = false, $file = false) {
219
+        if ($this->config->getSystemValue('debug', false)) {
220
+            // allows chrome workspace mapping in debug mode
221
+            return "";
222
+        }
223
+        $themingSuffix = '';
224
+        $v = [];
225
+
226
+        if ($this->config->getSystemValue('installed', false)) {
227
+            if (\OC::$server->getAppManager()->isInstalled('theming')) {
228
+                $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
229
+            }
230
+            $v = \OC_App::getAppVersions();
231
+        }
232
+
233
+        // Try the webroot path for a match
234
+        if ($path !== false && $path !== '') {
235
+            $appName = $this->getAppNamefromPath($path);
236
+            if(array_key_exists($appName, $v)) {
237
+                $appVersion = $v[$appName];
238
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
239
+            }
240
+        }
241
+        // fallback to the file path instead
242
+        if ($file !== false && $file !== '') {
243
+            $appName = $this->getAppNamefromPath($file);
244
+            if(array_key_exists($appName, $v)) {
245
+                $appVersion = $v[$appName];
246
+                return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix;
247
+            }
248
+        }
249
+
250
+        return '?v=' . self::$versionHash . $themingSuffix;
251
+    }
252
+
253
+    /**
254
+     * @param array $styles
255
+     * @return array
256
+     */
257
+    static public function findStylesheetFiles($styles, $compileScss = true) {
258
+        // Read the selected theme from the config file
259
+        $theme = \OC_Util::getTheme();
260
+
261
+        if($compileScss) {
262
+            $SCSSCacher = \OC::$server->query(SCSSCacher::class);
263
+        } else {
264
+            $SCSSCacher = null;
265
+        }
266
+
267
+        $locator = new \OC\Template\CSSResourceLocator(
268
+            \OC::$server->getLogger(),
269
+            $theme,
270
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
271
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
272
+            $SCSSCacher
273
+        );
274
+        $locator->find($styles);
275
+        return $locator->getResources();
276
+    }
277
+
278
+    /**
279
+     * @param string $path
280
+     * @return string|boolean
281
+     */
282
+    public function getAppNamefromPath($path) {
283
+        if ($path !== '' && is_string($path)) {
284
+            $pathParts = explode('/', $path);
285
+            if ($pathParts[0] === 'css') {
286
+                // This is a scss request
287
+                return $pathParts[1];
288
+            }
289
+            return end($pathParts);
290
+        }
291
+        return false;
292
+
293
+    }
294
+
295
+    /**
296
+     * @param array $scripts
297
+     * @return array
298
+     */
299
+    static public function findJavascriptFiles($scripts) {
300
+        // Read the selected theme from the config file
301
+        $theme = \OC_Util::getTheme();
302
+
303
+        $locator = new \OC\Template\JSResourceLocator(
304
+            \OC::$server->getLogger(),
305
+            $theme,
306
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
307
+            array( \OC::$SERVERROOT => \OC::$WEBROOT ),
308
+            new JSCombiner(
309
+                \OC::$server->getAppDataDir('js'),
310
+                \OC::$server->getURLGenerator(),
311
+                \OC::$server->getMemCacheFactory()->createDistributed('JS'),
312
+                \OC::$server->getSystemConfig(),
313
+                \OC::$server->getLogger()
314
+            )
315
+            );
316
+        $locator->find($scripts);
317
+        return $locator->getResources();
318
+    }
319
+
320
+    /**
321
+     * Converts the absolute file path to a relative path from \OC::$SERVERROOT
322
+     * @param string $filePath Absolute path
323
+     * @return string Relative path
324
+     * @throws \Exception If $filePath is not under \OC::$SERVERROOT
325
+     */
326
+    public static function convertToRelativePath($filePath) {
327
+        $relativePath = explode(\OC::$SERVERROOT, $filePath);
328
+        if(count($relativePath) !== 2) {
329
+            throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
330
+        }
331
+
332
+        return $relativePath[1];
333
+    }
334 334
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Template/PublicTemplateResponse.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -33,126 +33,126 @@
 block discarded – undo
33 33
  */
34 34
 class PublicTemplateResponse extends TemplateResponse {
35 35
 
36
-	private $headerTitle = '';
37
-	private $headerDetails = '';
38
-	private $headerActions = [];
39
-
40
-	/**
41
-	 * PublicTemplateResponse constructor.
42
-	 *
43
-	 * @param string $appName
44
-	 * @param string $templateName
45
-	 * @param array $params
46
-	 * @since 14.0.0
47
-	 */
48
-	public function __construct(string $appName, string $templateName, array $params = array()) {
49
-		parent::__construct($appName, $templateName, $params, 'public');
50
-		\OC_Util::addScript('core', 'public/publicpage');
51
-	}
52
-
53
-	/**
54
-	 * @param string $title
55
-	 * @since 14.0.0
56
-	 */
57
-	public function setHeaderTitle(string $title) {
58
-		$this->headerTitle = $title;
59
-	}
60
-
61
-	/**
62
-	 * @return string
63
-	 * @since 14.0.0
64
-	 */
65
-	public function getHeaderTitle(): string {
66
-		return $this->headerTitle;
67
-	}
68
-
69
-	/**
70
-	 * @param string $details
71
-	 * @since 14.0.0
72
-	 */
73
-	public function setHeaderDetails(string $details) {
74
-		$this->headerDetails = $details;
75
-	}
76
-
77
-	/**
78
-	 * @return string
79
-	 * @since 14.0.0
80
-	 */
81
-	public function getHeaderDetails(): string {
82
-		return $this->headerDetails;
83
-	}
84
-
85
-	/**
86
-	 * @param array $actions
87
-	 * @since 14.0.0
88
-	 */
89
-	public function setHeaderActions(array $actions) {
90
-		foreach ($actions as $action) {
91
-			if ($actions instanceof IMenuAction) {
92
-				throw new \InvalidArgumentException('Actions must be of type IMenuAction');
93
-			}
94
-			$this->headerActions[] = $action;
95
-		}
96
-	}
97
-
98
-	/**
99
-	 * @param IMenuAction $action
100
-	 * @since 14.0.0
101
-	 */
102
-	public function addAction(IMenuAction $action) {
103
-		$this->headerActions[] = $action;
104
-	}
105
-
106
-	/**
107
-	 * @return IMenuAction
108
-	 * @since 14.0.0
109
-	 */
110
-	public function getPrimaryAction(): IMenuAction {
111
-		$lowest = null;
112
-		foreach ($this->headerActions as $action) {
113
-			if($lowest === null || $action->getPriority() < $lowest->getPriority()) {
114
-				$lowest = $action;
115
-			}
116
-		}
117
-		return $lowest;
118
-	}
119
-
120
-	/**
121
-	 * @return int
122
-	 * @since 14.0.0
123
-	 */
124
-	public function getActionCount(): int {
125
-		return count($this->headerActions);
126
-	}
127
-
128
-	/**
129
-	 * @return IMenuAction[]
130
-	 * @since 14.0.0
131
-	 */
132
-	public function getOtherActions(): array {
133
-		$list = [];
134
-		$primary = $this->getPrimaryAction();
135
-		foreach ($this->headerActions as $action) {
136
-			if($primary !== $action) {
137
-				$list[] = $action;
138
-			}
139
-		}
140
-		usort($list, function(IMenuAction $a, IMenuAction $b) {
141
-			return $a->getPriority() > $b->getPriority();
142
-		});
143
-		return $list;
144
-	}
145
-
146
-	/**
147
-	 * @return string
148
-	 * @since 14.0.0
149
-	 */
150
-	public function render() {
151
-		$params = array_merge($this->getParams(), [
152
-			'template' => $this,
153
-		]);
154
-		$this->setParams($params);
155
-		return  parent::render();
156
-	}
36
+    private $headerTitle = '';
37
+    private $headerDetails = '';
38
+    private $headerActions = [];
39
+
40
+    /**
41
+     * PublicTemplateResponse constructor.
42
+     *
43
+     * @param string $appName
44
+     * @param string $templateName
45
+     * @param array $params
46
+     * @since 14.0.0
47
+     */
48
+    public function __construct(string $appName, string $templateName, array $params = array()) {
49
+        parent::__construct($appName, $templateName, $params, 'public');
50
+        \OC_Util::addScript('core', 'public/publicpage');
51
+    }
52
+
53
+    /**
54
+     * @param string $title
55
+     * @since 14.0.0
56
+     */
57
+    public function setHeaderTitle(string $title) {
58
+        $this->headerTitle = $title;
59
+    }
60
+
61
+    /**
62
+     * @return string
63
+     * @since 14.0.0
64
+     */
65
+    public function getHeaderTitle(): string {
66
+        return $this->headerTitle;
67
+    }
68
+
69
+    /**
70
+     * @param string $details
71
+     * @since 14.0.0
72
+     */
73
+    public function setHeaderDetails(string $details) {
74
+        $this->headerDetails = $details;
75
+    }
76
+
77
+    /**
78
+     * @return string
79
+     * @since 14.0.0
80
+     */
81
+    public function getHeaderDetails(): string {
82
+        return $this->headerDetails;
83
+    }
84
+
85
+    /**
86
+     * @param array $actions
87
+     * @since 14.0.0
88
+     */
89
+    public function setHeaderActions(array $actions) {
90
+        foreach ($actions as $action) {
91
+            if ($actions instanceof IMenuAction) {
92
+                throw new \InvalidArgumentException('Actions must be of type IMenuAction');
93
+            }
94
+            $this->headerActions[] = $action;
95
+        }
96
+    }
97
+
98
+    /**
99
+     * @param IMenuAction $action
100
+     * @since 14.0.0
101
+     */
102
+    public function addAction(IMenuAction $action) {
103
+        $this->headerActions[] = $action;
104
+    }
105
+
106
+    /**
107
+     * @return IMenuAction
108
+     * @since 14.0.0
109
+     */
110
+    public function getPrimaryAction(): IMenuAction {
111
+        $lowest = null;
112
+        foreach ($this->headerActions as $action) {
113
+            if($lowest === null || $action->getPriority() < $lowest->getPriority()) {
114
+                $lowest = $action;
115
+            }
116
+        }
117
+        return $lowest;
118
+    }
119
+
120
+    /**
121
+     * @return int
122
+     * @since 14.0.0
123
+     */
124
+    public function getActionCount(): int {
125
+        return count($this->headerActions);
126
+    }
127
+
128
+    /**
129
+     * @return IMenuAction[]
130
+     * @since 14.0.0
131
+     */
132
+    public function getOtherActions(): array {
133
+        $list = [];
134
+        $primary = $this->getPrimaryAction();
135
+        foreach ($this->headerActions as $action) {
136
+            if($primary !== $action) {
137
+                $list[] = $action;
138
+            }
139
+        }
140
+        usort($list, function(IMenuAction $a, IMenuAction $b) {
141
+            return $a->getPriority() > $b->getPriority();
142
+        });
143
+        return $list;
144
+    }
145
+
146
+    /**
147
+     * @return string
148
+     * @since 14.0.0
149
+     */
150
+    public function render() {
151
+        $params = array_merge($this->getParams(), [
152
+            'template' => $this,
153
+        ]);
154
+        $this->setParams($params);
155
+        return  parent::render();
156
+    }
157 157
 
158 158
 }
159 159
\ No newline at end of file
Please login to merge, or discard this patch.