Passed
Push — master ( 9d8e1e...a5b0f4 )
by Roeland
13:05 queued 14s
created
lib/private/legacy/template.php 2 patches
Indentation   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -47,315 +47,315 @@
 block discarded – undo
47 47
  */
48 48
 class OC_Template extends \OC\Template\Base {
49 49
 
50
-	/** @var string */
51
-	private $renderAs; // Create a full page?
52
-
53
-	/** @var string */
54
-	private $path; // The path to the template
55
-
56
-	/** @var array */
57
-	private $headers = array(); //custom headers
58
-
59
-	/** @var string */
60
-	protected $app; // app id
61
-
62
-	protected static $initTemplateEngineFirstRun = true;
63
-
64
-	/**
65
-	 * Constructor
66
-	 *
67
-	 * @param string $app app providing the template
68
-	 * @param string $name of the template file (without suffix)
69
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
70
-	 *                         produce a full page in the according layout. For
71
-	 *                         now, $renderAs can be set to "guest", "user" or
72
-	 *                         "admin".
73
-	 * @param bool $registerCall = true
74
-	 */
75
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
76
-		// Read the selected theme from the config file
77
-		self::initTemplateEngine($renderAs);
78
-
79
-		$theme = OC_Util::getTheme();
80
-
81
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
82
-
83
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
84
-		$l10n = \OC::$server->getL10N($parts[0]);
85
-		/** @var \OCP\Defaults $themeDefaults */
86
-		$themeDefaults = \OC::$server->query(\OCP\Defaults::class);
87
-
88
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
89
-
90
-		// Set the private data
91
-		$this->renderAs = $renderAs;
92
-		$this->path = $path;
93
-		$this->app = $app;
94
-
95
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
96
-	}
97
-
98
-	/**
99
-	 * @param string $renderAs
100
-	 */
101
-	public static function initTemplateEngine($renderAs) {
102
-		if (self::$initTemplateEngineFirstRun){
103
-
104
-			//apps that started before the template initialization can load their own scripts/styles
105
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
106
-			//meaning the last script/style in this list will be loaded first
107
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
108
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
109
-					OC_Util::addScript ( 'backgroundjobs', null, true );
110
-				}
111
-			}
112
-			OC_Util::addStyle('css-variables', null, true);
113
-			OC_Util::addStyle('server', null, true);
114
-			OC_Util::addTranslations('core', null, true);
115
-
116
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false)) {
117
-				OC_Util::addStyle('search', 'results');
118
-				OC_Util::addScript('search', 'search', true);
119
-				OC_Util::addScript('search', 'searchprovider');
120
-				OC_Util::addScript('merged-template-prepend', null, true);
121
-				OC_Util::addScript('files/fileinfo');
122
-				OC_Util::addScript('files/client');
123
-			}
124
-			OC_Util::addScript('core', 'dist/main', true);
125
-
126
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
127
-				// shim for the davclient.js library
128
-				\OCP\Util::addScript('files/iedavclient');
129
-			}
130
-
131
-			self::$initTemplateEngineFirstRun = false;
132
-		}
133
-
134
-	}
135
-
136
-
137
-	/**
138
-	 * find the template with the given name
139
-	 * @param string $name of the template file (without suffix)
140
-	 *
141
-	 * Will select the template file for the selected theme.
142
-	 * Checking all the possible locations.
143
-	 * @param string $theme
144
-	 * @param string $app
145
-	 * @return string[]
146
-	 */
147
-	protected function findTemplate($theme, $app, $name) {
148
-		// Check if it is a app template or not.
149
-		if( $app !== '' ) {
150
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
151
-		} else {
152
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
153
-		}
154
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
155
-		$template = $locator->find($name);
156
-		$path = $locator->getPath();
157
-		return array($path, $template);
158
-	}
159
-
160
-	/**
161
-	 * Add a custom element to the header
162
-	 * @param string $tag tag name of the element
163
-	 * @param array $attributes array of attributes for the element
164
-	 * @param string $text the text content for the element. If $text is null then the
165
-	 * element will be written as empty element. So use "" to get a closing tag.
166
-	 */
167
-	public function addHeader($tag, $attributes, $text=null) {
168
-		$this->headers[]= array(
169
-			'tag' => $tag,
170
-			'attributes' => $attributes,
171
-			'text' => $text
172
-		);
173
-	}
174
-
175
-	/**
176
-	 * Process the template
177
-	 * @return boolean|string
178
-	 *
179
-	 * This function process the template. If $this->renderAs is set, it
180
-	 * will produce a full page.
181
-	 */
182
-	public function fetchPage($additionalParams = null) {
183
-		$data = parent::fetchPage($additionalParams);
184
-
185
-		if( $this->renderAs ) {
186
-			$page = new TemplateLayout($this->renderAs, $this->app);
187
-
188
-			if(is_array($additionalParams)) {
189
-				foreach ($additionalParams as $key => $value) {
190
-					$page->assign($key, $value);
191
-				}
192
-			}
193
-
194
-			// Add custom headers
195
-			$headers = '';
196
-			foreach(OC_Util::$headers as $header) {
197
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
198
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
199
-					$headers .= ' defer';
200
-				}
201
-				foreach($header['attributes'] as $name=>$value) {
202
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
203
-				}
204
-				if ($header['text'] !== null) {
205
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
206
-				} else {
207
-					$headers .= '/>';
208
-				}
209
-			}
210
-
211
-			$page->assign('headers', $headers);
212
-
213
-			$page->assign('content', $data);
214
-			return $page->fetchPage($additionalParams);
215
-		}
216
-
217
-		return $data;
218
-	}
219
-
220
-	/**
221
-	 * Include template
222
-	 *
223
-	 * @param string $file
224
-	 * @param array|null $additionalParams
225
-	 * @return string returns content of included template
226
-	 *
227
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
228
-	 * do this.
229
-	 */
230
-	public function inc( $file, $additionalParams = null ) {
231
-		return $this->load($this->path.$file.'.php', $additionalParams);
232
-	}
233
-
234
-	/**
235
-	 * Shortcut to print a simple page for users
236
-	 * @param string $application The application we render the template for
237
-	 * @param string $name Name of the template
238
-	 * @param array $parameters Parameters for the template
239
-	 * @return boolean|null
240
-	 */
241
-	public static function printUserPage( $application, $name, $parameters = array() ) {
242
-		$content = new OC_Template( $application, $name, "user" );
243
-		foreach( $parameters as $key => $value ) {
244
-			$content->assign( $key, $value );
245
-		}
246
-		print $content->printPage();
247
-	}
248
-
249
-	/**
250
-	 * Shortcut to print a simple page for admins
251
-	 * @param string $application The application we render the template for
252
-	 * @param string $name Name of the template
253
-	 * @param array $parameters Parameters for the template
254
-	 * @return bool
255
-	 */
256
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
257
-		$content = new OC_Template( $application, $name, "admin" );
258
-		foreach( $parameters as $key => $value ) {
259
-			$content->assign( $key, $value );
260
-		}
261
-		return $content->printPage();
262
-	}
263
-
264
-	/**
265
-	 * Shortcut to print a simple page for guests
266
-	 * @param string $application The application we render the template for
267
-	 * @param string $name Name of the template
268
-	 * @param array|string $parameters Parameters for the template
269
-	 * @return bool
270
-	 */
271
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
272
-		$content = new OC_Template($application, $name, $name === 'error' ? $name : 'guest');
273
-		foreach( $parameters as $key => $value ) {
274
-			$content->assign( $key, $value );
275
-		}
276
-		return $content->printPage();
277
-	}
278
-
279
-	/**
280
-	 * Print a fatal error page and terminates the script
281
-	 * @param string $error_msg The error message to show
282
-	 * @param string $hint An optional hint message - needs to be properly escape
283
-	 * @param int $statusCode
284
-	 * @suppress PhanAccessMethodInternal
285
-	 */
286
-	public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
287
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
288
-			\OC_App::loadApp('theming');
289
-		}
290
-
291
-
292
-		if ($error_msg === $hint) {
293
-			// If the hint is the same as the message there is no need to display it twice.
294
-			$hint = '';
295
-		}
296
-
297
-		http_response_code($statusCode);
298
-		try {
299
-			$content = new \OC_Template( '', 'error', 'error', false );
300
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
301
-			$content->assign( 'errors', $errors );
302
-			$content->printPage();
303
-		} catch (\Exception $e) {
304
-			$logger = \OC::$server->getLogger();
305
-			$logger->error("$error_msg $hint", ['app' => 'core']);
306
-			$logger->logException($e, ['app' => 'core']);
307
-
308
-			header('Content-Type: text/plain; charset=utf-8');
309
-			print("$error_msg $hint");
310
-		}
311
-		die();
312
-	}
313
-
314
-	/**
315
-	 * print error page using Exception details
316
-	 * @param Exception|Throwable $exception
317
-	 * @param int $statusCode
318
-	 * @return bool|string
319
-	 * @suppress PhanAccessMethodInternal
320
-	 */
321
-	public static function printExceptionErrorPage($exception, $statusCode = 503) {
322
-		http_response_code($statusCode);
323
-		try {
324
-			$request = \OC::$server->getRequest();
325
-			$content = new \OC_Template('', 'exception', 'error', false);
326
-			$content->assign('errorClass', get_class($exception));
327
-			$content->assign('errorMsg', $exception->getMessage());
328
-			$content->assign('errorCode', $exception->getCode());
329
-			$content->assign('file', $exception->getFile());
330
-			$content->assign('line', $exception->getLine());
331
-			$content->assign('trace', $exception->getTraceAsString());
332
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
333
-			$content->assign('remoteAddr', $request->getRemoteAddress());
334
-			$content->assign('requestID', $request->getId());
335
-			$content->printPage();
336
-		} catch (\Exception $e) {
337
-			try {
338
-				$logger = \OC::$server->getLogger();
339
-				$logger->logException($exception, ['app' => 'core']);
340
-				$logger->logException($e, ['app' => 'core']);
341
-			} catch (Throwable $e) {
342
-				// no way to log it properly - but to avoid a white page of death we send some output
343
-				header('Content-Type: text/plain; charset=utf-8');
344
-				print("Internal Server Error\n\n");
345
-				print("The server encountered an internal error and was unable to complete your request.\n");
346
-				print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
347
-				print("More details can be found in the server log.\n");
348
-
349
-				// and then throw it again to log it at least to the web server error log
350
-				throw $e;
351
-			}
352
-
353
-			header('Content-Type: text/plain; charset=utf-8');
354
-			print("Internal Server Error\n\n");
355
-			print("The server encountered an internal error and was unable to complete your request.\n");
356
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
357
-			print("More details can be found in the server log.\n");
358
-		}
359
-		die();
360
-	}
50
+    /** @var string */
51
+    private $renderAs; // Create a full page?
52
+
53
+    /** @var string */
54
+    private $path; // The path to the template
55
+
56
+    /** @var array */
57
+    private $headers = array(); //custom headers
58
+
59
+    /** @var string */
60
+    protected $app; // app id
61
+
62
+    protected static $initTemplateEngineFirstRun = true;
63
+
64
+    /**
65
+     * Constructor
66
+     *
67
+     * @param string $app app providing the template
68
+     * @param string $name of the template file (without suffix)
69
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
70
+     *                         produce a full page in the according layout. For
71
+     *                         now, $renderAs can be set to "guest", "user" or
72
+     *                         "admin".
73
+     * @param bool $registerCall = true
74
+     */
75
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
76
+        // Read the selected theme from the config file
77
+        self::initTemplateEngine($renderAs);
78
+
79
+        $theme = OC_Util::getTheme();
80
+
81
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
82
+
83
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
84
+        $l10n = \OC::$server->getL10N($parts[0]);
85
+        /** @var \OCP\Defaults $themeDefaults */
86
+        $themeDefaults = \OC::$server->query(\OCP\Defaults::class);
87
+
88
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
89
+
90
+        // Set the private data
91
+        $this->renderAs = $renderAs;
92
+        $this->path = $path;
93
+        $this->app = $app;
94
+
95
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
96
+    }
97
+
98
+    /**
99
+     * @param string $renderAs
100
+     */
101
+    public static function initTemplateEngine($renderAs) {
102
+        if (self::$initTemplateEngineFirstRun){
103
+
104
+            //apps that started before the template initialization can load their own scripts/styles
105
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
106
+            //meaning the last script/style in this list will be loaded first
107
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
108
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
109
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
110
+                }
111
+            }
112
+            OC_Util::addStyle('css-variables', null, true);
113
+            OC_Util::addStyle('server', null, true);
114
+            OC_Util::addTranslations('core', null, true);
115
+
116
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false)) {
117
+                OC_Util::addStyle('search', 'results');
118
+                OC_Util::addScript('search', 'search', true);
119
+                OC_Util::addScript('search', 'searchprovider');
120
+                OC_Util::addScript('merged-template-prepend', null, true);
121
+                OC_Util::addScript('files/fileinfo');
122
+                OC_Util::addScript('files/client');
123
+            }
124
+            OC_Util::addScript('core', 'dist/main', true);
125
+
126
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
127
+                // shim for the davclient.js library
128
+                \OCP\Util::addScript('files/iedavclient');
129
+            }
130
+
131
+            self::$initTemplateEngineFirstRun = false;
132
+        }
133
+
134
+    }
135
+
136
+
137
+    /**
138
+     * find the template with the given name
139
+     * @param string $name of the template file (without suffix)
140
+     *
141
+     * Will select the template file for the selected theme.
142
+     * Checking all the possible locations.
143
+     * @param string $theme
144
+     * @param string $app
145
+     * @return string[]
146
+     */
147
+    protected function findTemplate($theme, $app, $name) {
148
+        // Check if it is a app template or not.
149
+        if( $app !== '' ) {
150
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
151
+        } else {
152
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
153
+        }
154
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
155
+        $template = $locator->find($name);
156
+        $path = $locator->getPath();
157
+        return array($path, $template);
158
+    }
159
+
160
+    /**
161
+     * Add a custom element to the header
162
+     * @param string $tag tag name of the element
163
+     * @param array $attributes array of attributes for the element
164
+     * @param string $text the text content for the element. If $text is null then the
165
+     * element will be written as empty element. So use "" to get a closing tag.
166
+     */
167
+    public function addHeader($tag, $attributes, $text=null) {
168
+        $this->headers[]= array(
169
+            'tag' => $tag,
170
+            'attributes' => $attributes,
171
+            'text' => $text
172
+        );
173
+    }
174
+
175
+    /**
176
+     * Process the template
177
+     * @return boolean|string
178
+     *
179
+     * This function process the template. If $this->renderAs is set, it
180
+     * will produce a full page.
181
+     */
182
+    public function fetchPage($additionalParams = null) {
183
+        $data = parent::fetchPage($additionalParams);
184
+
185
+        if( $this->renderAs ) {
186
+            $page = new TemplateLayout($this->renderAs, $this->app);
187
+
188
+            if(is_array($additionalParams)) {
189
+                foreach ($additionalParams as $key => $value) {
190
+                    $page->assign($key, $value);
191
+                }
192
+            }
193
+
194
+            // Add custom headers
195
+            $headers = '';
196
+            foreach(OC_Util::$headers as $header) {
197
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
198
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
199
+                    $headers .= ' defer';
200
+                }
201
+                foreach($header['attributes'] as $name=>$value) {
202
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
203
+                }
204
+                if ($header['text'] !== null) {
205
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
206
+                } else {
207
+                    $headers .= '/>';
208
+                }
209
+            }
210
+
211
+            $page->assign('headers', $headers);
212
+
213
+            $page->assign('content', $data);
214
+            return $page->fetchPage($additionalParams);
215
+        }
216
+
217
+        return $data;
218
+    }
219
+
220
+    /**
221
+     * Include template
222
+     *
223
+     * @param string $file
224
+     * @param array|null $additionalParams
225
+     * @return string returns content of included template
226
+     *
227
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
228
+     * do this.
229
+     */
230
+    public function inc( $file, $additionalParams = null ) {
231
+        return $this->load($this->path.$file.'.php', $additionalParams);
232
+    }
233
+
234
+    /**
235
+     * Shortcut to print a simple page for users
236
+     * @param string $application The application we render the template for
237
+     * @param string $name Name of the template
238
+     * @param array $parameters Parameters for the template
239
+     * @return boolean|null
240
+     */
241
+    public static function printUserPage( $application, $name, $parameters = array() ) {
242
+        $content = new OC_Template( $application, $name, "user" );
243
+        foreach( $parameters as $key => $value ) {
244
+            $content->assign( $key, $value );
245
+        }
246
+        print $content->printPage();
247
+    }
248
+
249
+    /**
250
+     * Shortcut to print a simple page for admins
251
+     * @param string $application The application we render the template for
252
+     * @param string $name Name of the template
253
+     * @param array $parameters Parameters for the template
254
+     * @return bool
255
+     */
256
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
257
+        $content = new OC_Template( $application, $name, "admin" );
258
+        foreach( $parameters as $key => $value ) {
259
+            $content->assign( $key, $value );
260
+        }
261
+        return $content->printPage();
262
+    }
263
+
264
+    /**
265
+     * Shortcut to print a simple page for guests
266
+     * @param string $application The application we render the template for
267
+     * @param string $name Name of the template
268
+     * @param array|string $parameters Parameters for the template
269
+     * @return bool
270
+     */
271
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
272
+        $content = new OC_Template($application, $name, $name === 'error' ? $name : 'guest');
273
+        foreach( $parameters as $key => $value ) {
274
+            $content->assign( $key, $value );
275
+        }
276
+        return $content->printPage();
277
+    }
278
+
279
+    /**
280
+     * Print a fatal error page and terminates the script
281
+     * @param string $error_msg The error message to show
282
+     * @param string $hint An optional hint message - needs to be properly escape
283
+     * @param int $statusCode
284
+     * @suppress PhanAccessMethodInternal
285
+     */
286
+    public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
287
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
288
+            \OC_App::loadApp('theming');
289
+        }
290
+
291
+
292
+        if ($error_msg === $hint) {
293
+            // If the hint is the same as the message there is no need to display it twice.
294
+            $hint = '';
295
+        }
296
+
297
+        http_response_code($statusCode);
298
+        try {
299
+            $content = new \OC_Template( '', 'error', 'error', false );
300
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
301
+            $content->assign( 'errors', $errors );
302
+            $content->printPage();
303
+        } catch (\Exception $e) {
304
+            $logger = \OC::$server->getLogger();
305
+            $logger->error("$error_msg $hint", ['app' => 'core']);
306
+            $logger->logException($e, ['app' => 'core']);
307
+
308
+            header('Content-Type: text/plain; charset=utf-8');
309
+            print("$error_msg $hint");
310
+        }
311
+        die();
312
+    }
313
+
314
+    /**
315
+     * print error page using Exception details
316
+     * @param Exception|Throwable $exception
317
+     * @param int $statusCode
318
+     * @return bool|string
319
+     * @suppress PhanAccessMethodInternal
320
+     */
321
+    public static function printExceptionErrorPage($exception, $statusCode = 503) {
322
+        http_response_code($statusCode);
323
+        try {
324
+            $request = \OC::$server->getRequest();
325
+            $content = new \OC_Template('', 'exception', 'error', false);
326
+            $content->assign('errorClass', get_class($exception));
327
+            $content->assign('errorMsg', $exception->getMessage());
328
+            $content->assign('errorCode', $exception->getCode());
329
+            $content->assign('file', $exception->getFile());
330
+            $content->assign('line', $exception->getLine());
331
+            $content->assign('trace', $exception->getTraceAsString());
332
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
333
+            $content->assign('remoteAddr', $request->getRemoteAddress());
334
+            $content->assign('requestID', $request->getId());
335
+            $content->printPage();
336
+        } catch (\Exception $e) {
337
+            try {
338
+                $logger = \OC::$server->getLogger();
339
+                $logger->logException($exception, ['app' => 'core']);
340
+                $logger->logException($e, ['app' => 'core']);
341
+            } catch (Throwable $e) {
342
+                // no way to log it properly - but to avoid a white page of death we send some output
343
+                header('Content-Type: text/plain; charset=utf-8');
344
+                print("Internal Server Error\n\n");
345
+                print("The server encountered an internal error and was unable to complete your request.\n");
346
+                print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
347
+                print("More details can be found in the server log.\n");
348
+
349
+                // and then throw it again to log it at least to the web server error log
350
+                throw $e;
351
+            }
352
+
353
+            header('Content-Type: text/plain; charset=utf-8');
354
+            print("Internal Server Error\n\n");
355
+            print("The server encountered an internal error and was unable to complete your request.\n");
356
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
357
+            print("More details can be found in the server log.\n");
358
+        }
359
+        die();
360
+    }
361 361
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *                         "admin".
73 73
 	 * @param bool $registerCall = true
74 74
 	 */
75
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
75
+	public function __construct($app, $name, $renderAs = "", $registerCall = true) {
76 76
 		// Read the selected theme from the config file
77 77
 		self::initTemplateEngine($renderAs);
78 78
 
@@ -99,21 +99,21 @@  discard block
 block discarded – undo
99 99
 	 * @param string $renderAs
100 100
 	 */
101 101
 	public static function initTemplateEngine($renderAs) {
102
-		if (self::$initTemplateEngineFirstRun){
102
+		if (self::$initTemplateEngineFirstRun) {
103 103
 
104 104
 			//apps that started before the template initialization can load their own scripts/styles
105 105
 			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
106 106
 			//meaning the last script/style in this list will be loaded first
107
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
108
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
109
-					OC_Util::addScript ( 'backgroundjobs', null, true );
107
+			if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
108
+				if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
109
+					OC_Util::addScript('backgroundjobs', null, true);
110 110
 				}
111 111
 			}
112 112
 			OC_Util::addStyle('css-variables', null, true);
113 113
 			OC_Util::addStyle('server', null, true);
114 114
 			OC_Util::addTranslations('core', null, true);
115 115
 
116
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false)) {
116
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
117 117
 				OC_Util::addStyle('search', 'results');
118 118
 				OC_Util::addScript('search', 'search', true);
119 119
 				OC_Util::addScript('search', 'searchprovider');
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 	 */
147 147
 	protected function findTemplate($theme, $app, $name) {
148 148
 		// Check if it is a app template or not.
149
-		if( $app !== '' ) {
149
+		if ($app !== '') {
150 150
 			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
151 151
 		} else {
152 152
 			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
153 153
 		}
154
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
154
+		$locator = new \OC\Template\TemplateFileLocator($dirs);
155 155
 		$template = $locator->find($name);
156 156
 		$path = $locator->getPath();
157 157
 		return array($path, $template);
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	 * @param string $text the text content for the element. If $text is null then the
165 165
 	 * element will be written as empty element. So use "" to get a closing tag.
166 166
 	 */
167
-	public function addHeader($tag, $attributes, $text=null) {
168
-		$this->headers[]= array(
167
+	public function addHeader($tag, $attributes, $text = null) {
168
+		$this->headers[] = array(
169 169
 			'tag' => $tag,
170 170
 			'attributes' => $attributes,
171 171
 			'text' => $text
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 	public function fetchPage($additionalParams = null) {
183 183
 		$data = parent::fetchPage($additionalParams);
184 184
 
185
-		if( $this->renderAs ) {
185
+		if ($this->renderAs) {
186 186
 			$page = new TemplateLayout($this->renderAs, $this->app);
187 187
 
188
-			if(is_array($additionalParams)) {
188
+			if (is_array($additionalParams)) {
189 189
 				foreach ($additionalParams as $key => $value) {
190 190
 					$page->assign($key, $value);
191 191
 				}
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
 
194 194
 			// Add custom headers
195 195
 			$headers = '';
196
-			foreach(OC_Util::$headers as $header) {
196
+			foreach (OC_Util::$headers as $header) {
197 197
 				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
198
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
198
+				if (strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes'])))) {
199 199
 					$headers .= ' defer';
200 200
 				}
201
-				foreach($header['attributes'] as $name=>$value) {
201
+				foreach ($header['attributes'] as $name=>$value) {
202 202
 					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
203 203
 				}
204 204
 				if ($header['text'] !== null) {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 * Includes another template. use <?php echo $this->inc('template'); ?> to
228 228
 	 * do this.
229 229
 	 */
230
-	public function inc( $file, $additionalParams = null ) {
230
+	public function inc($file, $additionalParams = null) {
231 231
 		return $this->load($this->path.$file.'.php', $additionalParams);
232 232
 	}
233 233
 
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 	 * @param array $parameters Parameters for the template
239 239
 	 * @return boolean|null
240 240
 	 */
241
-	public static function printUserPage( $application, $name, $parameters = array() ) {
242
-		$content = new OC_Template( $application, $name, "user" );
243
-		foreach( $parameters as $key => $value ) {
244
-			$content->assign( $key, $value );
241
+	public static function printUserPage($application, $name, $parameters = array()) {
242
+		$content = new OC_Template($application, $name, "user");
243
+		foreach ($parameters as $key => $value) {
244
+			$content->assign($key, $value);
245 245
 		}
246 246
 		print $content->printPage();
247 247
 	}
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
 	 * @param array $parameters Parameters for the template
254 254
 	 * @return bool
255 255
 	 */
256
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
257
-		$content = new OC_Template( $application, $name, "admin" );
258
-		foreach( $parameters as $key => $value ) {
259
-			$content->assign( $key, $value );
256
+	public static function printAdminPage($application, $name, $parameters = array()) {
257
+		$content = new OC_Template($application, $name, "admin");
258
+		foreach ($parameters as $key => $value) {
259
+			$content->assign($key, $value);
260 260
 		}
261 261
 		return $content->printPage();
262 262
 	}
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 	 * @param array|string $parameters Parameters for the template
269 269
 	 * @return bool
270 270
 	 */
271
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
271
+	public static function printGuestPage($application, $name, $parameters = array()) {
272 272
 		$content = new OC_Template($application, $name, $name === 'error' ? $name : 'guest');
273
-		foreach( $parameters as $key => $value ) {
274
-			$content->assign( $key, $value );
273
+		foreach ($parameters as $key => $value) {
274
+			$content->assign($key, $value);
275 275
 		}
276 276
 		return $content->printPage();
277 277
 	}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 * @param int $statusCode
284 284
 	 * @suppress PhanAccessMethodInternal
285 285
 	 */
286
-	public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
286
+	public static function printErrorPage($error_msg, $hint = '', $statusCode = 500) {
287 287
 		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
288 288
 			\OC_App::loadApp('theming');
289 289
 		}
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 
297 297
 		http_response_code($statusCode);
298 298
 		try {
299
-			$content = new \OC_Template( '', 'error', 'error', false );
299
+			$content = new \OC_Template('', 'error', 'error', false);
300 300
 			$errors = array(array('error' => $error_msg, 'hint' => $hint));
301
-			$content->assign( 'errors', $errors );
301
+			$content->assign('errors', $errors);
302 302
 			$content->printPage();
303 303
 		} catch (\Exception $e) {
304 304
 			$logger = \OC::$server->getLogger();
Please login to merge, or discard this patch.
core/templates/installation.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 script('core', [
3
-	'dist/install'
3
+    'dist/install'
4 4
 ]);
5 5
 ?>
6 6
 <input type='hidden' id='hasMySQL' value='<?php p($_['hasMySQL']) ?>'>
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
 		<legend><strong><?php p($l->t('Security warning'));?></strong></legend>
30 30
 		<p><?php p($l->t('Your data directory and files are probably accessible from the internet because the .htaccess file does not work.'));?><br>
31 31
 		<?php print_unescaped($l->t(
32
-			'For information how to properly configure your server, please see the <a href="%s" target="_blank" rel="noreferrer noopener">documentation</a>.',
33
-			[link_to_docs('admin-install')]
34
-		)); ?></p>
32
+            'For information how to properly configure your server, please see the <a href="%s" target="_blank" rel="noreferrer noopener">documentation</a>.',
33
+            [link_to_docs('admin-install')]
34
+        )); ?></p>
35 35
 	</fieldset>
36 36
 	<?php endif; ?>
37 37
 	<fieldset id="adminaccount">
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	<?php if(!$_['dbIsSet'] OR count($_['errors']) > 0): ?>
76 76
 	<fieldset id='databaseBackend'>
77 77
 		<?php if($_['hasMySQL'] or $_['hasPostgreSQL'] or $_['hasOracle'])
78
-			$hasOtherDB = true; else $hasOtherDB =false; //other than SQLite ?>
78
+            $hasOtherDB = true; else $hasOtherDB =false; //other than SQLite ?>
79 79
 		<legend><?php p($l->t( 'Configure the database' )); ?></legend>
80 80
 		<div id="selectDbType">
81 81
 		<?php foreach($_['databases'] as $type => $label): ?>
Please login to merge, or discard this patch.