Passed
Push — master ( b6d327...cbd17c )
by Morris
10:51
created
lib/private/legacy/template.php 2 patches
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -46,313 +46,313 @@
 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('css-variables', null, true);
113
-			OC_Util::addStyle('server', null, true);
114
-			OC_Util::addTranslations("core", null, true);
115
-			OC_Util::addStyle('search', 'results');
116
-			OC_Util::addScript('search', 'search', true);
117
-			OC_Util::addScript('search', 'searchprovider');
118
-			OC_Util::addScript('merged-template-prepend', null, true);
119
-			OC_Util::addScript('files/fileinfo');
120
-			OC_Util::addScript('files/client');
121
-			OC_Util::addScript('core', 'dist/main', true);
122
-
123
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
124
-				// shim for the davclient.js library
125
-				\OCP\Util::addScript('files/iedavclient');
126
-			}
127
-
128
-			self::$initTemplateEngineFirstRun = false;
129
-		}
130
-
131
-	}
132
-
133
-
134
-	/**
135
-	 * find the template with the given name
136
-	 * @param string $name of the template file (without suffix)
137
-	 *
138
-	 * Will select the template file for the selected theme.
139
-	 * Checking all the possible locations.
140
-	 * @param string $theme
141
-	 * @param string $app
142
-	 * @return string[]
143
-	 */
144
-	protected function findTemplate($theme, $app, $name) {
145
-		// Check if it is a app template or not.
146
-		if( $app !== '' ) {
147
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
148
-		} else {
149
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
150
-		}
151
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
152
-		$template = $locator->find($name);
153
-		$path = $locator->getPath();
154
-		return array($path, $template);
155
-	}
156
-
157
-	/**
158
-	 * Add a custom element to the header
159
-	 * @param string $tag tag name of the element
160
-	 * @param array $attributes array of attributes for the element
161
-	 * @param string $text the text content for the element. If $text is null then the
162
-	 * element will be written as empty element. So use "" to get a closing tag.
163
-	 */
164
-	public function addHeader($tag, $attributes, $text=null) {
165
-		$this->headers[]= array(
166
-			'tag' => $tag,
167
-			'attributes' => $attributes,
168
-			'text' => $text
169
-		);
170
-	}
171
-
172
-	/**
173
-	 * Process the template
174
-	 * @return boolean|string
175
-	 *
176
-	 * This function process the template. If $this->renderAs is set, it
177
-	 * will produce a full page.
178
-	 */
179
-	public function fetchPage($additionalParams = null) {
180
-		$data = parent::fetchPage($additionalParams);
181
-
182
-		if( $this->renderAs ) {
183
-			$page = new TemplateLayout($this->renderAs, $this->app);
184
-
185
-			if(is_array($additionalParams)) {
186
-				foreach ($additionalParams as $key => $value) {
187
-					$page->assign($key, $value);
188
-				}
189
-			}
190
-
191
-			// Add custom headers
192
-			$headers = '';
193
-			foreach(OC_Util::$headers as $header) {
194
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
195
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
196
-					$headers .= ' defer';
197
-				}
198
-				foreach($header['attributes'] as $name=>$value) {
199
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
200
-				}
201
-				if ($header['text'] !== null) {
202
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
203
-				} else {
204
-					$headers .= '/>';
205
-				}
206
-			}
207
-
208
-			$page->assign('headers', $headers);
209
-
210
-			$page->assign('content', $data);
211
-			return $page->fetchPage($additionalParams);
212
-		}
213
-
214
-		return $data;
215
-	}
216
-
217
-	/**
218
-	 * Include template
219
-	 *
220
-	 * @param string $file
221
-	 * @param array|null $additionalParams
222
-	 * @return string returns content of included template
223
-	 *
224
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
225
-	 * do this.
226
-	 */
227
-	public function inc( $file, $additionalParams = null ) {
228
-		return $this->load($this->path.$file.'.php', $additionalParams);
229
-	}
230
-
231
-	/**
232
-	 * Shortcut to print a simple page for users
233
-	 * @param string $application The application we render the template for
234
-	 * @param string $name Name of the template
235
-	 * @param array $parameters Parameters for the template
236
-	 * @return boolean|null
237
-	 */
238
-	public static function printUserPage( $application, $name, $parameters = array() ) {
239
-		$content = new OC_Template( $application, $name, "user" );
240
-		foreach( $parameters as $key => $value ) {
241
-			$content->assign( $key, $value );
242
-		}
243
-		print $content->printPage();
244
-	}
245
-
246
-	/**
247
-	 * Shortcut to print a simple page for admins
248
-	 * @param string $application The application we render the template for
249
-	 * @param string $name Name of the template
250
-	 * @param array $parameters Parameters for the template
251
-	 * @return bool
252
-	 */
253
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
254
-		$content = new OC_Template( $application, $name, "admin" );
255
-		foreach( $parameters as $key => $value ) {
256
-			$content->assign( $key, $value );
257
-		}
258
-		return $content->printPage();
259
-	}
260
-
261
-	/**
262
-	 * Shortcut to print a simple page for guests
263
-	 * @param string $application The application we render the template for
264
-	 * @param string $name Name of the template
265
-	 * @param array|string $parameters Parameters for the template
266
-	 * @return bool
267
-	 */
268
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
269
-		$content = new OC_Template( $application, $name, "guest" );
270
-		foreach( $parameters as $key => $value ) {
271
-			$content->assign( $key, $value );
272
-		}
273
-		return $content->printPage();
274
-	}
275
-
276
-	/**
277
-	 * Print a fatal error page and terminates the script
278
-	 * @param string $error_msg The error message to show
279
-	 * @param string $hint An optional hint message - needs to be properly escape
280
-	 * @param int $statusCode
281
-	 * @suppress PhanAccessMethodInternal
282
-	 */
283
-	public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
284
-		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
285
-			\OC_App::loadApp('theming');
286
-		}
287
-
288
-
289
-		if ($error_msg === $hint) {
290
-			// If the hint is the same as the message there is no need to display it twice.
291
-			$hint = '';
292
-		}
293
-
294
-		http_response_code($statusCode);
295
-		try {
296
-			$content = new \OC_Template( '', 'error', 'error', false );
297
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
298
-			$content->assign( 'errors', $errors );
299
-			$content->printPage();
300
-		} catch (\Exception $e) {
301
-			$logger = \OC::$server->getLogger();
302
-			$logger->error("$error_msg $hint", ['app' => 'core']);
303
-			$logger->logException($e, ['app' => 'core']);
304
-
305
-			header('Content-Type: text/plain; charset=utf-8');
306
-			print("$error_msg $hint");
307
-		}
308
-		die();
309
-	}
310
-
311
-	/**
312
-	 * print error page using Exception details
313
-	 * @param Exception|Throwable $exception
314
-	 * @param int $statusCode
315
-	 * @return bool|string
316
-	 * @suppress PhanAccessMethodInternal
317
-	 */
318
-	public static function printExceptionErrorPage($exception, $statusCode = 503) {
319
-		http_response_code($statusCode);
320
-		try {
321
-			$request = \OC::$server->getRequest();
322
-			$content = new \OC_Template('', 'exception', 'error', false);
323
-			$content->assign('errorClass', get_class($exception));
324
-			$content->assign('errorMsg', $exception->getMessage());
325
-			$content->assign('errorCode', $exception->getCode());
326
-			$content->assign('file', $exception->getFile());
327
-			$content->assign('line', $exception->getLine());
328
-			$content->assign('trace', $exception->getTraceAsString());
329
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
330
-			$content->assign('remoteAddr', $request->getRemoteAddress());
331
-			$content->assign('requestID', $request->getId());
332
-			$content->printPage();
333
-		} catch (\Exception $e) {
334
-			try {
335
-				$logger = \OC::$server->getLogger();
336
-				$logger->logException($exception, ['app' => 'core']);
337
-				$logger->logException($e, ['app' => 'core']);
338
-			} catch (Throwable $e) {
339
-				// no way to log it properly - but to avoid a white page of death we send some output
340
-				header('Content-Type: text/plain; charset=utf-8');
341
-				print("Internal Server Error\n\n");
342
-				print("The server encountered an internal error and was unable to complete your request.\n");
343
-				print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
344
-				print("More details can be found in the server log.\n");
345
-
346
-				// and then throw it again to log it at least to the web server error log
347
-				throw $e;
348
-			}
349
-
350
-			header('Content-Type: text/plain; charset=utf-8');
351
-			print("Internal Server Error\n\n");
352
-			print("The server encountered an internal error and was unable to complete your request.\n");
353
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
354
-			print("More details can be found in the server log.\n");
355
-		}
356
-		die();
357
-	}
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('css-variables', null, true);
113
+            OC_Util::addStyle('server', null, true);
114
+            OC_Util::addTranslations("core", null, true);
115
+            OC_Util::addStyle('search', 'results');
116
+            OC_Util::addScript('search', 'search', true);
117
+            OC_Util::addScript('search', 'searchprovider');
118
+            OC_Util::addScript('merged-template-prepend', null, true);
119
+            OC_Util::addScript('files/fileinfo');
120
+            OC_Util::addScript('files/client');
121
+            OC_Util::addScript('core', 'dist/main', true);
122
+
123
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
124
+                // shim for the davclient.js library
125
+                \OCP\Util::addScript('files/iedavclient');
126
+            }
127
+
128
+            self::$initTemplateEngineFirstRun = false;
129
+        }
130
+
131
+    }
132
+
133
+
134
+    /**
135
+     * find the template with the given name
136
+     * @param string $name of the template file (without suffix)
137
+     *
138
+     * Will select the template file for the selected theme.
139
+     * Checking all the possible locations.
140
+     * @param string $theme
141
+     * @param string $app
142
+     * @return string[]
143
+     */
144
+    protected function findTemplate($theme, $app, $name) {
145
+        // Check if it is a app template or not.
146
+        if( $app !== '' ) {
147
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
148
+        } else {
149
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
150
+        }
151
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
152
+        $template = $locator->find($name);
153
+        $path = $locator->getPath();
154
+        return array($path, $template);
155
+    }
156
+
157
+    /**
158
+     * Add a custom element to the header
159
+     * @param string $tag tag name of the element
160
+     * @param array $attributes array of attributes for the element
161
+     * @param string $text the text content for the element. If $text is null then the
162
+     * element will be written as empty element. So use "" to get a closing tag.
163
+     */
164
+    public function addHeader($tag, $attributes, $text=null) {
165
+        $this->headers[]= array(
166
+            'tag' => $tag,
167
+            'attributes' => $attributes,
168
+            'text' => $text
169
+        );
170
+    }
171
+
172
+    /**
173
+     * Process the template
174
+     * @return boolean|string
175
+     *
176
+     * This function process the template. If $this->renderAs is set, it
177
+     * will produce a full page.
178
+     */
179
+    public function fetchPage($additionalParams = null) {
180
+        $data = parent::fetchPage($additionalParams);
181
+
182
+        if( $this->renderAs ) {
183
+            $page = new TemplateLayout($this->renderAs, $this->app);
184
+
185
+            if(is_array($additionalParams)) {
186
+                foreach ($additionalParams as $key => $value) {
187
+                    $page->assign($key, $value);
188
+                }
189
+            }
190
+
191
+            // Add custom headers
192
+            $headers = '';
193
+            foreach(OC_Util::$headers as $header) {
194
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
195
+                if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
196
+                    $headers .= ' defer';
197
+                }
198
+                foreach($header['attributes'] as $name=>$value) {
199
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
200
+                }
201
+                if ($header['text'] !== null) {
202
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
203
+                } else {
204
+                    $headers .= '/>';
205
+                }
206
+            }
207
+
208
+            $page->assign('headers', $headers);
209
+
210
+            $page->assign('content', $data);
211
+            return $page->fetchPage($additionalParams);
212
+        }
213
+
214
+        return $data;
215
+    }
216
+
217
+    /**
218
+     * Include template
219
+     *
220
+     * @param string $file
221
+     * @param array|null $additionalParams
222
+     * @return string returns content of included template
223
+     *
224
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
225
+     * do this.
226
+     */
227
+    public function inc( $file, $additionalParams = null ) {
228
+        return $this->load($this->path.$file.'.php', $additionalParams);
229
+    }
230
+
231
+    /**
232
+     * Shortcut to print a simple page for users
233
+     * @param string $application The application we render the template for
234
+     * @param string $name Name of the template
235
+     * @param array $parameters Parameters for the template
236
+     * @return boolean|null
237
+     */
238
+    public static function printUserPage( $application, $name, $parameters = array() ) {
239
+        $content = new OC_Template( $application, $name, "user" );
240
+        foreach( $parameters as $key => $value ) {
241
+            $content->assign( $key, $value );
242
+        }
243
+        print $content->printPage();
244
+    }
245
+
246
+    /**
247
+     * Shortcut to print a simple page for admins
248
+     * @param string $application The application we render the template for
249
+     * @param string $name Name of the template
250
+     * @param array $parameters Parameters for the template
251
+     * @return bool
252
+     */
253
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
254
+        $content = new OC_Template( $application, $name, "admin" );
255
+        foreach( $parameters as $key => $value ) {
256
+            $content->assign( $key, $value );
257
+        }
258
+        return $content->printPage();
259
+    }
260
+
261
+    /**
262
+     * Shortcut to print a simple page for guests
263
+     * @param string $application The application we render the template for
264
+     * @param string $name Name of the template
265
+     * @param array|string $parameters Parameters for the template
266
+     * @return bool
267
+     */
268
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
269
+        $content = new OC_Template( $application, $name, "guest" );
270
+        foreach( $parameters as $key => $value ) {
271
+            $content->assign( $key, $value );
272
+        }
273
+        return $content->printPage();
274
+    }
275
+
276
+    /**
277
+     * Print a fatal error page and terminates the script
278
+     * @param string $error_msg The error message to show
279
+     * @param string $hint An optional hint message - needs to be properly escape
280
+     * @param int $statusCode
281
+     * @suppress PhanAccessMethodInternal
282
+     */
283
+    public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
284
+        if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
285
+            \OC_App::loadApp('theming');
286
+        }
287
+
288
+
289
+        if ($error_msg === $hint) {
290
+            // If the hint is the same as the message there is no need to display it twice.
291
+            $hint = '';
292
+        }
293
+
294
+        http_response_code($statusCode);
295
+        try {
296
+            $content = new \OC_Template( '', 'error', 'error', false );
297
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
298
+            $content->assign( 'errors', $errors );
299
+            $content->printPage();
300
+        } catch (\Exception $e) {
301
+            $logger = \OC::$server->getLogger();
302
+            $logger->error("$error_msg $hint", ['app' => 'core']);
303
+            $logger->logException($e, ['app' => 'core']);
304
+
305
+            header('Content-Type: text/plain; charset=utf-8');
306
+            print("$error_msg $hint");
307
+        }
308
+        die();
309
+    }
310
+
311
+    /**
312
+     * print error page using Exception details
313
+     * @param Exception|Throwable $exception
314
+     * @param int $statusCode
315
+     * @return bool|string
316
+     * @suppress PhanAccessMethodInternal
317
+     */
318
+    public static function printExceptionErrorPage($exception, $statusCode = 503) {
319
+        http_response_code($statusCode);
320
+        try {
321
+            $request = \OC::$server->getRequest();
322
+            $content = new \OC_Template('', 'exception', 'error', false);
323
+            $content->assign('errorClass', get_class($exception));
324
+            $content->assign('errorMsg', $exception->getMessage());
325
+            $content->assign('errorCode', $exception->getCode());
326
+            $content->assign('file', $exception->getFile());
327
+            $content->assign('line', $exception->getLine());
328
+            $content->assign('trace', $exception->getTraceAsString());
329
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
330
+            $content->assign('remoteAddr', $request->getRemoteAddress());
331
+            $content->assign('requestID', $request->getId());
332
+            $content->printPage();
333
+        } catch (\Exception $e) {
334
+            try {
335
+                $logger = \OC::$server->getLogger();
336
+                $logger->logException($exception, ['app' => 'core']);
337
+                $logger->logException($e, ['app' => 'core']);
338
+            } catch (Throwable $e) {
339
+                // no way to log it properly - but to avoid a white page of death we send some output
340
+                header('Content-Type: text/plain; charset=utf-8');
341
+                print("Internal Server Error\n\n");
342
+                print("The server encountered an internal error and was unable to complete your request.\n");
343
+                print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
344
+                print("More details can be found in the server log.\n");
345
+
346
+                // and then throw it again to log it at least to the web server error log
347
+                throw $e;
348
+            }
349
+
350
+            header('Content-Type: text/plain; charset=utf-8');
351
+            print("Internal Server Error\n\n");
352
+            print("The server encountered an internal error and was unable to complete your request.\n");
353
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
354
+            print("More details can be found in the server log.\n");
355
+        }
356
+        die();
357
+    }
358 358
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *                         "admin".
72 72
 	 * @param bool $registerCall = true
73 73
 	 */
74
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
74
+	public function __construct($app, $name, $renderAs = "", $registerCall = true) {
75 75
 		// Read the selected theme from the config file
76 76
 		self::initTemplateEngine($renderAs);
77 77
 
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 	 * @param string $renderAs
99 99
 	 */
100 100
 	public static function initTemplateEngine($renderAs) {
101
-		if (self::$initTemplateEngineFirstRun){
101
+		if (self::$initTemplateEngineFirstRun) {
102 102
 
103 103
 			//apps that started before the template initialization can load their own scripts/styles
104 104
 			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
105 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 );
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 109
 				}
110 110
 			}
111 111
 
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
 	 */
144 144
 	protected function findTemplate($theme, $app, $name) {
145 145
 		// Check if it is a app template or not.
146
-		if( $app !== '' ) {
146
+		if ($app !== '') {
147 147
 			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
148 148
 		} else {
149 149
 			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
150 150
 		}
151
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
151
+		$locator = new \OC\Template\TemplateFileLocator($dirs);
152 152
 		$template = $locator->find($name);
153 153
 		$path = $locator->getPath();
154 154
 		return array($path, $template);
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param string $text the text content for the element. If $text is null then the
162 162
 	 * element will be written as empty element. So use "" to get a closing tag.
163 163
 	 */
164
-	public function addHeader($tag, $attributes, $text=null) {
165
-		$this->headers[]= array(
164
+	public function addHeader($tag, $attributes, $text = null) {
165
+		$this->headers[] = array(
166 166
 			'tag' => $tag,
167 167
 			'attributes' => $attributes,
168 168
 			'text' => $text
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 	public function fetchPage($additionalParams = null) {
180 180
 		$data = parent::fetchPage($additionalParams);
181 181
 
182
-		if( $this->renderAs ) {
182
+		if ($this->renderAs) {
183 183
 			$page = new TemplateLayout($this->renderAs, $this->app);
184 184
 
185
-			if(is_array($additionalParams)) {
185
+			if (is_array($additionalParams)) {
186 186
 				foreach ($additionalParams as $key => $value) {
187 187
 					$page->assign($key, $value);
188 188
 				}
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
 
191 191
 			// Add custom headers
192 192
 			$headers = '';
193
-			foreach(OC_Util::$headers as $header) {
193
+			foreach (OC_Util::$headers as $header) {
194 194
 				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
195
-				if ( strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes']))) ) {
195
+				if (strcasecmp($header['tag'], 'script') === 0 && in_array('src', array_map('strtolower', array_keys($header['attributes'])))) {
196 196
 					$headers .= ' defer';
197 197
 				}
198
-				foreach($header['attributes'] as $name=>$value) {
198
+				foreach ($header['attributes'] as $name=>$value) {
199 199
 					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
200 200
 				}
201 201
 				if ($header['text'] !== null) {
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 * Includes another template. use <?php echo $this->inc('template'); ?> to
225 225
 	 * do this.
226 226
 	 */
227
-	public function inc( $file, $additionalParams = null ) {
227
+	public function inc($file, $additionalParams = null) {
228 228
 		return $this->load($this->path.$file.'.php', $additionalParams);
229 229
 	}
230 230
 
@@ -235,10 +235,10 @@  discard block
 block discarded – undo
235 235
 	 * @param array $parameters Parameters for the template
236 236
 	 * @return boolean|null
237 237
 	 */
238
-	public static function printUserPage( $application, $name, $parameters = array() ) {
239
-		$content = new OC_Template( $application, $name, "user" );
240
-		foreach( $parameters as $key => $value ) {
241
-			$content->assign( $key, $value );
238
+	public static function printUserPage($application, $name, $parameters = array()) {
239
+		$content = new OC_Template($application, $name, "user");
240
+		foreach ($parameters as $key => $value) {
241
+			$content->assign($key, $value);
242 242
 		}
243 243
 		print $content->printPage();
244 244
 	}
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
 	 * @param array $parameters Parameters for the template
251 251
 	 * @return bool
252 252
 	 */
253
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
254
-		$content = new OC_Template( $application, $name, "admin" );
255
-		foreach( $parameters as $key => $value ) {
256
-			$content->assign( $key, $value );
253
+	public static function printAdminPage($application, $name, $parameters = array()) {
254
+		$content = new OC_Template($application, $name, "admin");
255
+		foreach ($parameters as $key => $value) {
256
+			$content->assign($key, $value);
257 257
 		}
258 258
 		return $content->printPage();
259 259
 	}
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	 * @param array|string $parameters Parameters for the template
266 266
 	 * @return bool
267 267
 	 */
268
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
269
-		$content = new OC_Template( $application, $name, "guest" );
270
-		foreach( $parameters as $key => $value ) {
271
-			$content->assign( $key, $value );
268
+	public static function printGuestPage($application, $name, $parameters = array()) {
269
+		$content = new OC_Template($application, $name, "guest");
270
+		foreach ($parameters as $key => $value) {
271
+			$content->assign($key, $value);
272 272
 		}
273 273
 		return $content->printPage();
274 274
 	}
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 * @param int $statusCode
281 281
 	 * @suppress PhanAccessMethodInternal
282 282
 	 */
283
-	public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) {
283
+	public static function printErrorPage($error_msg, $hint = '', $statusCode = 500) {
284 284
 		if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
285 285
 			\OC_App::loadApp('theming');
286 286
 		}
@@ -293,9 +293,9 @@  discard block
 block discarded – undo
293 293
 
294 294
 		http_response_code($statusCode);
295 295
 		try {
296
-			$content = new \OC_Template( '', 'error', 'error', false );
296
+			$content = new \OC_Template('', 'error', 'error', false);
297 297
 			$errors = array(array('error' => $error_msg, 'hint' => $hint));
298
-			$content->assign( 'errors', $errors );
298
+			$content->assign('errors', $errors);
299 299
 			$content->printPage();
300 300
 		} catch (\Exception $e) {
301 301
 			$logger = \OC::$server->getLogger();
Please login to merge, or discard this patch.