@@ -44,346 +44,346 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class OC_Template extends \OC\Template\Base { |
| 46 | 46 | |
| 47 | - /** @var string */ |
|
| 48 | - private $renderAs; // Create a full page? |
|
| 49 | - |
|
| 50 | - /** @var string */ |
|
| 51 | - private $path; // The path to the template |
|
| 52 | - |
|
| 53 | - /** @var array */ |
|
| 54 | - private $headers = array(); //custom headers |
|
| 55 | - |
|
| 56 | - /** @var string */ |
|
| 57 | - protected $app; // app id |
|
| 58 | - |
|
| 59 | - protected static $initTemplateEngineFirstRun = true; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Constructor |
|
| 63 | - * |
|
| 64 | - * @param string $app app providing the template |
|
| 65 | - * @param string $name of the template file (without suffix) |
|
| 66 | - * @param string $renderAs If $renderAs is set, OC_Template will try to |
|
| 67 | - * produce a full page in the according layout. For |
|
| 68 | - * now, $renderAs can be set to "guest", "user" or |
|
| 69 | - * "admin". |
|
| 70 | - * @param bool $registerCall = true |
|
| 71 | - */ |
|
| 72 | - public function __construct( $app, $name, $renderAs = "", $registerCall = true ) { |
|
| 73 | - // Read the selected theme from the config file |
|
| 74 | - self::initTemplateEngine($renderAs); |
|
| 75 | - |
|
| 76 | - $theme = OC_Util::getTheme(); |
|
| 77 | - |
|
| 78 | - $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : ''; |
|
| 79 | - |
|
| 80 | - $parts = explode('/', $app); // fix translation when app is something like core/lostpassword |
|
| 81 | - $l10n = \OC::$server->getL10N($parts[0]); |
|
| 82 | - $themeDefaults = \OC::$server->getThemingDefaults(); |
|
| 83 | - |
|
| 84 | - list($path, $template) = $this->findTemplate($theme, $app, $name); |
|
| 85 | - |
|
| 86 | - // Set the private data |
|
| 87 | - $this->renderAs = $renderAs; |
|
| 88 | - $this->path = $path; |
|
| 89 | - $this->app = $app; |
|
| 90 | - |
|
| 91 | - parent::__construct($template, $requestToken, $l10n, $themeDefaults); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $renderAs |
|
| 96 | - */ |
|
| 97 | - public static function initTemplateEngine($renderAs) { |
|
| 98 | - if (self::$initTemplateEngineFirstRun){ |
|
| 99 | - |
|
| 100 | - //apps that started before the template initialization can load their own scripts/styles |
|
| 101 | - //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true |
|
| 102 | - //meaning the last script/style in this list will be loaded first |
|
| 103 | - if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
| 104 | - if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { |
|
| 105 | - OC_Util::addScript ( 'backgroundjobs', null, true ); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - OC_Util::addStyle('jquery-ui-fixes',null,true); |
|
| 110 | - OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true); |
|
| 111 | - OC_Util::addStyle('server', null, true); |
|
| 112 | - |
|
| 113 | - // avatars |
|
| 114 | - \OC_Util::addScript('jquery.avatar', null, true); |
|
| 115 | - \OC_Util::addScript('placeholder', null, true); |
|
| 116 | - |
|
| 117 | - OC_Util::addVendorScript('select2/select2'); |
|
| 118 | - OC_Util::addVendorStyle('select2/select2', null, true); |
|
| 119 | - OC_Util::addScript('select2-toggleselect'); |
|
| 120 | - |
|
| 121 | - OC_Util::addScript('oc-backbone', null, true); |
|
| 122 | - OC_Util::addVendorScript('core', 'backbone/backbone', true); |
|
| 123 | - OC_Util::addVendorScript('snapjs/dist/latest/snap', null, true); |
|
| 124 | - OC_Util::addScript('mimetypelist', null, true); |
|
| 125 | - OC_Util::addScript('mimetype', null, true); |
|
| 126 | - OC_Util::addScript("apps", null, true); |
|
| 127 | - OC_Util::addScript("oc-requesttoken", null, true); |
|
| 128 | - OC_Util::addScript('search', 'search', true); |
|
| 129 | - OC_Util::addScript("config", null, true); |
|
| 130 | - OC_Util::addScript("public/appconfig", null, true); |
|
| 131 | - OC_Util::addScript("eventsource", null, true); |
|
| 132 | - OC_Util::addScript("octemplate", null, true); |
|
| 133 | - OC_Util::addTranslations("core", null, true); |
|
| 134 | - OC_Util::addScript("l10n", null, true); |
|
| 135 | - OC_Util::addScript("js", null, true); |
|
| 136 | - OC_Util::addScript("oc-dialogs", null, true); |
|
| 137 | - OC_Util::addScript("jquery.ocdialog", null, true); |
|
| 138 | - OC_Util::addScript("jquery-ui-fixes"); |
|
| 139 | - OC_Util::addStyle("jquery.ocdialog"); |
|
| 140 | - OC_Util::addScript('files/fileinfo'); |
|
| 141 | - OC_Util::addScript('files/client'); |
|
| 142 | - |
|
| 143 | - // Add the stuff we need always |
|
| 144 | - // following logic will import all vendor libraries that are |
|
| 145 | - // specified in core/js/core.json |
|
| 146 | - $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); |
|
| 147 | - if($fileContent !== false) { |
|
| 148 | - $coreDependencies = json_decode($fileContent, true); |
|
| 149 | - foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
| 150 | - // remove trailing ".js" as addVendorScript will append it |
|
| 151 | - OC_Util::addVendorScript( |
|
| 152 | - substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - throw new \Exception('Cannot read core/js/core.json'); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) { |
|
| 159 | - // polyfill for btoa/atob for IE friends |
|
| 160 | - OC_Util::addVendorScript('base64/base64'); |
|
| 161 | - // shim for the davclient.js library |
|
| 162 | - \OCP\Util::addScript('files/iedavclient'); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - self::$initTemplateEngineFirstRun = false; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * find the template with the given name |
|
| 173 | - * @param string $name of the template file (without suffix) |
|
| 174 | - * |
|
| 175 | - * Will select the template file for the selected theme. |
|
| 176 | - * Checking all the possible locations. |
|
| 177 | - * @param string $theme |
|
| 178 | - * @param string $app |
|
| 179 | - * @return string[] |
|
| 180 | - */ |
|
| 181 | - protected function findTemplate($theme, $app, $name) { |
|
| 182 | - // Check if it is a app template or not. |
|
| 183 | - if( $app !== '' ) { |
|
| 184 | - $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app)); |
|
| 185 | - } else { |
|
| 186 | - $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT); |
|
| 187 | - } |
|
| 188 | - $locator = new \OC\Template\TemplateFileLocator( $dirs ); |
|
| 189 | - $template = $locator->find($name); |
|
| 190 | - $path = $locator->getPath(); |
|
| 191 | - return array($path, $template); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Add a custom element to the header |
|
| 196 | - * @param string $tag tag name of the element |
|
| 197 | - * @param array $attributes array of attributes for the element |
|
| 198 | - * @param string $text the text content for the element. If $text is null then the |
|
| 199 | - * element will be written as empty element. So use "" to get a closing tag. |
|
| 200 | - */ |
|
| 201 | - public function addHeader($tag, $attributes, $text=null) { |
|
| 202 | - $this->headers[]= array( |
|
| 203 | - 'tag' => $tag, |
|
| 204 | - 'attributes' => $attributes, |
|
| 205 | - 'text' => $text |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Process the template |
|
| 211 | - * @return boolean|string |
|
| 212 | - * |
|
| 213 | - * This function process the template. If $this->renderAs is set, it |
|
| 214 | - * will produce a full page. |
|
| 215 | - */ |
|
| 216 | - public function fetchPage($additionalParams = null) { |
|
| 217 | - $data = parent::fetchPage($additionalParams); |
|
| 218 | - |
|
| 219 | - if( $this->renderAs ) { |
|
| 220 | - $page = new TemplateLayout($this->renderAs, $this->app); |
|
| 221 | - |
|
| 222 | - // Add custom headers |
|
| 223 | - $headers = ''; |
|
| 224 | - foreach(OC_Util::$headers as $header) { |
|
| 225 | - $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); |
|
| 226 | - foreach($header['attributes'] as $name=>$value) { |
|
| 227 | - $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; |
|
| 228 | - } |
|
| 229 | - if ($header['text'] !== null) { |
|
| 230 | - $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>'; |
|
| 231 | - } else { |
|
| 232 | - $headers .= '/>'; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $page->assign('headers', $headers); |
|
| 237 | - |
|
| 238 | - $page->assign('content', $data); |
|
| 239 | - return $page->fetchPage(); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return $data; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Include template |
|
| 247 | - * |
|
| 248 | - * @param string $file |
|
| 249 | - * @param array|null $additionalParams |
|
| 250 | - * @return string returns content of included template |
|
| 251 | - * |
|
| 252 | - * Includes another template. use <?php echo $this->inc('template'); ?> to |
|
| 253 | - * do this. |
|
| 254 | - */ |
|
| 255 | - public function inc( $file, $additionalParams = null ) { |
|
| 256 | - return $this->load($this->path.$file.'.php', $additionalParams); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Shortcut to print a simple page for users |
|
| 261 | - * @param string $application The application we render the template for |
|
| 262 | - * @param string $name Name of the template |
|
| 263 | - * @param array $parameters Parameters for the template |
|
| 264 | - * @return boolean|null |
|
| 265 | - */ |
|
| 266 | - public static function printUserPage( $application, $name, $parameters = array() ) { |
|
| 267 | - $content = new OC_Template( $application, $name, "user" ); |
|
| 268 | - foreach( $parameters as $key => $value ) { |
|
| 269 | - $content->assign( $key, $value ); |
|
| 270 | - } |
|
| 271 | - print $content->printPage(); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Shortcut to print a simple page for admins |
|
| 276 | - * @param string $application The application we render the template for |
|
| 277 | - * @param string $name Name of the template |
|
| 278 | - * @param array $parameters Parameters for the template |
|
| 279 | - * @return bool |
|
| 280 | - */ |
|
| 281 | - public static function printAdminPage( $application, $name, $parameters = array() ) { |
|
| 282 | - $content = new OC_Template( $application, $name, "admin" ); |
|
| 283 | - foreach( $parameters as $key => $value ) { |
|
| 284 | - $content->assign( $key, $value ); |
|
| 285 | - } |
|
| 286 | - return $content->printPage(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Shortcut to print a simple page for guests |
|
| 291 | - * @param string $application The application we render the template for |
|
| 292 | - * @param string $name Name of the template |
|
| 293 | - * @param array|string $parameters Parameters for the template |
|
| 294 | - * @return bool |
|
| 295 | - */ |
|
| 296 | - public static function printGuestPage( $application, $name, $parameters = array() ) { |
|
| 297 | - $content = new OC_Template( $application, $name, "guest" ); |
|
| 298 | - foreach( $parameters as $key => $value ) { |
|
| 299 | - $content->assign( $key, $value ); |
|
| 300 | - } |
|
| 301 | - return $content->printPage(); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Print a fatal error page and terminates the script |
|
| 306 | - * @param string $error_msg The error message to show |
|
| 307 | - * @param string $hint An optional hint message - needs to be properly escaped |
|
| 308 | - */ |
|
| 309 | - public static function printErrorPage( $error_msg, $hint = '' ) { |
|
| 310 | - if ($error_msg === $hint) { |
|
| 311 | - // If the hint is the same as the message there is no need to display it twice. |
|
| 312 | - $hint = ''; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - try { |
|
| 316 | - $content = new \OC_Template( '', 'error', 'error', false ); |
|
| 317 | - $errors = array(array('error' => $error_msg, 'hint' => $hint)); |
|
| 318 | - $content->assign( 'errors', $errors ); |
|
| 319 | - $content->printPage(); |
|
| 320 | - } catch (\Exception $e) { |
|
| 321 | - $logger = \OC::$server->getLogger(); |
|
| 322 | - $logger->error("$error_msg $hint", ['app' => 'core']); |
|
| 323 | - $logger->logException($e, ['app' => 'core']); |
|
| 324 | - |
|
| 325 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 326 | - header('Content-Type: text/plain; charset=utf-8'); |
|
| 327 | - print("$error_msg $hint"); |
|
| 328 | - } |
|
| 329 | - die(); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * print error page using Exception details |
|
| 334 | - * @param Exception | Throwable $exception |
|
| 335 | - */ |
|
| 336 | - public static function printExceptionErrorPage($exception, $fetchPage = false) { |
|
| 337 | - try { |
|
| 338 | - $request = \OC::$server->getRequest(); |
|
| 339 | - $content = new \OC_Template('', 'exception', 'error', false); |
|
| 340 | - $content->assign('errorClass', get_class($exception)); |
|
| 341 | - $content->assign('errorMsg', $exception->getMessage()); |
|
| 342 | - $content->assign('errorCode', $exception->getCode()); |
|
| 343 | - $content->assign('file', $exception->getFile()); |
|
| 344 | - $content->assign('line', $exception->getLine()); |
|
| 345 | - $content->assign('trace', $exception->getTraceAsString()); |
|
| 346 | - $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); |
|
| 347 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 348 | - $content->assign('requestID', $request->getId()); |
|
| 349 | - if ($fetchPage) { |
|
| 350 | - return $content->fetchPage(); |
|
| 351 | - } |
|
| 352 | - $content->printPage(); |
|
| 353 | - } catch (\Exception $e) { |
|
| 354 | - $logger = \OC::$server->getLogger(); |
|
| 355 | - $logger->logException($exception, ['app' => 'core']); |
|
| 356 | - $logger->logException($e, ['app' => 'core']); |
|
| 357 | - |
|
| 358 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 359 | - header('Content-Type: text/plain; charset=utf-8'); |
|
| 360 | - print("Internal Server Error\n\n"); |
|
| 361 | - print("The server encountered an internal error and was unable to complete your request.\n"); |
|
| 362 | - print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
| 363 | - print("More details can be found in the server log.\n"); |
|
| 364 | - } |
|
| 365 | - die(); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * This is only here to reduce the dependencies in case of an exception to |
|
| 370 | - * still be able to print a plain error message. |
|
| 371 | - * |
|
| 372 | - * Returns the used HTTP protocol. |
|
| 373 | - * |
|
| 374 | - * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. |
|
| 375 | - * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead |
|
| 376 | - */ |
|
| 377 | - protected static function getHttpProtocol() { |
|
| 378 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 379 | - $validProtocols = [ |
|
| 380 | - 'HTTP/1.0', |
|
| 381 | - 'HTTP/1.1', |
|
| 382 | - 'HTTP/2', |
|
| 383 | - ]; |
|
| 384 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 385 | - return $claimedProtocol; |
|
| 386 | - } |
|
| 387 | - return 'HTTP/1.1'; |
|
| 388 | - } |
|
| 47 | + /** @var string */ |
|
| 48 | + private $renderAs; // Create a full page? |
|
| 49 | + |
|
| 50 | + /** @var string */ |
|
| 51 | + private $path; // The path to the template |
|
| 52 | + |
|
| 53 | + /** @var array */ |
|
| 54 | + private $headers = array(); //custom headers |
|
| 55 | + |
|
| 56 | + /** @var string */ |
|
| 57 | + protected $app; // app id |
|
| 58 | + |
|
| 59 | + protected static $initTemplateEngineFirstRun = true; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Constructor |
|
| 63 | + * |
|
| 64 | + * @param string $app app providing the template |
|
| 65 | + * @param string $name of the template file (without suffix) |
|
| 66 | + * @param string $renderAs If $renderAs is set, OC_Template will try to |
|
| 67 | + * produce a full page in the according layout. For |
|
| 68 | + * now, $renderAs can be set to "guest", "user" or |
|
| 69 | + * "admin". |
|
| 70 | + * @param bool $registerCall = true |
|
| 71 | + */ |
|
| 72 | + public function __construct( $app, $name, $renderAs = "", $registerCall = true ) { |
|
| 73 | + // Read the selected theme from the config file |
|
| 74 | + self::initTemplateEngine($renderAs); |
|
| 75 | + |
|
| 76 | + $theme = OC_Util::getTheme(); |
|
| 77 | + |
|
| 78 | + $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : ''; |
|
| 79 | + |
|
| 80 | + $parts = explode('/', $app); // fix translation when app is something like core/lostpassword |
|
| 81 | + $l10n = \OC::$server->getL10N($parts[0]); |
|
| 82 | + $themeDefaults = \OC::$server->getThemingDefaults(); |
|
| 83 | + |
|
| 84 | + list($path, $template) = $this->findTemplate($theme, $app, $name); |
|
| 85 | + |
|
| 86 | + // Set the private data |
|
| 87 | + $this->renderAs = $renderAs; |
|
| 88 | + $this->path = $path; |
|
| 89 | + $this->app = $app; |
|
| 90 | + |
|
| 91 | + parent::__construct($template, $requestToken, $l10n, $themeDefaults); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $renderAs |
|
| 96 | + */ |
|
| 97 | + public static function initTemplateEngine($renderAs) { |
|
| 98 | + if (self::$initTemplateEngineFirstRun){ |
|
| 99 | + |
|
| 100 | + //apps that started before the template initialization can load their own scripts/styles |
|
| 101 | + //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true |
|
| 102 | + //meaning the last script/style in this list will be loaded first |
|
| 103 | + if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
| 104 | + if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { |
|
| 105 | + OC_Util::addScript ( 'backgroundjobs', null, true ); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + OC_Util::addStyle('jquery-ui-fixes',null,true); |
|
| 110 | + OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true); |
|
| 111 | + OC_Util::addStyle('server', null, true); |
|
| 112 | + |
|
| 113 | + // avatars |
|
| 114 | + \OC_Util::addScript('jquery.avatar', null, true); |
|
| 115 | + \OC_Util::addScript('placeholder', null, true); |
|
| 116 | + |
|
| 117 | + OC_Util::addVendorScript('select2/select2'); |
|
| 118 | + OC_Util::addVendorStyle('select2/select2', null, true); |
|
| 119 | + OC_Util::addScript('select2-toggleselect'); |
|
| 120 | + |
|
| 121 | + OC_Util::addScript('oc-backbone', null, true); |
|
| 122 | + OC_Util::addVendorScript('core', 'backbone/backbone', true); |
|
| 123 | + OC_Util::addVendorScript('snapjs/dist/latest/snap', null, true); |
|
| 124 | + OC_Util::addScript('mimetypelist', null, true); |
|
| 125 | + OC_Util::addScript('mimetype', null, true); |
|
| 126 | + OC_Util::addScript("apps", null, true); |
|
| 127 | + OC_Util::addScript("oc-requesttoken", null, true); |
|
| 128 | + OC_Util::addScript('search', 'search', true); |
|
| 129 | + OC_Util::addScript("config", null, true); |
|
| 130 | + OC_Util::addScript("public/appconfig", null, true); |
|
| 131 | + OC_Util::addScript("eventsource", null, true); |
|
| 132 | + OC_Util::addScript("octemplate", null, true); |
|
| 133 | + OC_Util::addTranslations("core", null, true); |
|
| 134 | + OC_Util::addScript("l10n", null, true); |
|
| 135 | + OC_Util::addScript("js", null, true); |
|
| 136 | + OC_Util::addScript("oc-dialogs", null, true); |
|
| 137 | + OC_Util::addScript("jquery.ocdialog", null, true); |
|
| 138 | + OC_Util::addScript("jquery-ui-fixes"); |
|
| 139 | + OC_Util::addStyle("jquery.ocdialog"); |
|
| 140 | + OC_Util::addScript('files/fileinfo'); |
|
| 141 | + OC_Util::addScript('files/client'); |
|
| 142 | + |
|
| 143 | + // Add the stuff we need always |
|
| 144 | + // following logic will import all vendor libraries that are |
|
| 145 | + // specified in core/js/core.json |
|
| 146 | + $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); |
|
| 147 | + if($fileContent !== false) { |
|
| 148 | + $coreDependencies = json_decode($fileContent, true); |
|
| 149 | + foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
| 150 | + // remove trailing ".js" as addVendorScript will append it |
|
| 151 | + OC_Util::addVendorScript( |
|
| 152 | + substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + throw new \Exception('Cannot read core/js/core.json'); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) { |
|
| 159 | + // polyfill for btoa/atob for IE friends |
|
| 160 | + OC_Util::addVendorScript('base64/base64'); |
|
| 161 | + // shim for the davclient.js library |
|
| 162 | + \OCP\Util::addScript('files/iedavclient'); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + self::$initTemplateEngineFirstRun = false; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * find the template with the given name |
|
| 173 | + * @param string $name of the template file (without suffix) |
|
| 174 | + * |
|
| 175 | + * Will select the template file for the selected theme. |
|
| 176 | + * Checking all the possible locations. |
|
| 177 | + * @param string $theme |
|
| 178 | + * @param string $app |
|
| 179 | + * @return string[] |
|
| 180 | + */ |
|
| 181 | + protected function findTemplate($theme, $app, $name) { |
|
| 182 | + // Check if it is a app template or not. |
|
| 183 | + if( $app !== '' ) { |
|
| 184 | + $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app)); |
|
| 185 | + } else { |
|
| 186 | + $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT); |
|
| 187 | + } |
|
| 188 | + $locator = new \OC\Template\TemplateFileLocator( $dirs ); |
|
| 189 | + $template = $locator->find($name); |
|
| 190 | + $path = $locator->getPath(); |
|
| 191 | + return array($path, $template); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Add a custom element to the header |
|
| 196 | + * @param string $tag tag name of the element |
|
| 197 | + * @param array $attributes array of attributes for the element |
|
| 198 | + * @param string $text the text content for the element. If $text is null then the |
|
| 199 | + * element will be written as empty element. So use "" to get a closing tag. |
|
| 200 | + */ |
|
| 201 | + public function addHeader($tag, $attributes, $text=null) { |
|
| 202 | + $this->headers[]= array( |
|
| 203 | + 'tag' => $tag, |
|
| 204 | + 'attributes' => $attributes, |
|
| 205 | + 'text' => $text |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Process the template |
|
| 211 | + * @return boolean|string |
|
| 212 | + * |
|
| 213 | + * This function process the template. If $this->renderAs is set, it |
|
| 214 | + * will produce a full page. |
|
| 215 | + */ |
|
| 216 | + public function fetchPage($additionalParams = null) { |
|
| 217 | + $data = parent::fetchPage($additionalParams); |
|
| 218 | + |
|
| 219 | + if( $this->renderAs ) { |
|
| 220 | + $page = new TemplateLayout($this->renderAs, $this->app); |
|
| 221 | + |
|
| 222 | + // Add custom headers |
|
| 223 | + $headers = ''; |
|
| 224 | + foreach(OC_Util::$headers as $header) { |
|
| 225 | + $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); |
|
| 226 | + foreach($header['attributes'] as $name=>$value) { |
|
| 227 | + $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; |
|
| 228 | + } |
|
| 229 | + if ($header['text'] !== null) { |
|
| 230 | + $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>'; |
|
| 231 | + } else { |
|
| 232 | + $headers .= '/>'; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $page->assign('headers', $headers); |
|
| 237 | + |
|
| 238 | + $page->assign('content', $data); |
|
| 239 | + return $page->fetchPage(); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return $data; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Include template |
|
| 247 | + * |
|
| 248 | + * @param string $file |
|
| 249 | + * @param array|null $additionalParams |
|
| 250 | + * @return string returns content of included template |
|
| 251 | + * |
|
| 252 | + * Includes another template. use <?php echo $this->inc('template'); ?> to |
|
| 253 | + * do this. |
|
| 254 | + */ |
|
| 255 | + public function inc( $file, $additionalParams = null ) { |
|
| 256 | + return $this->load($this->path.$file.'.php', $additionalParams); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Shortcut to print a simple page for users |
|
| 261 | + * @param string $application The application we render the template for |
|
| 262 | + * @param string $name Name of the template |
|
| 263 | + * @param array $parameters Parameters for the template |
|
| 264 | + * @return boolean|null |
|
| 265 | + */ |
|
| 266 | + public static function printUserPage( $application, $name, $parameters = array() ) { |
|
| 267 | + $content = new OC_Template( $application, $name, "user" ); |
|
| 268 | + foreach( $parameters as $key => $value ) { |
|
| 269 | + $content->assign( $key, $value ); |
|
| 270 | + } |
|
| 271 | + print $content->printPage(); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Shortcut to print a simple page for admins |
|
| 276 | + * @param string $application The application we render the template for |
|
| 277 | + * @param string $name Name of the template |
|
| 278 | + * @param array $parameters Parameters for the template |
|
| 279 | + * @return bool |
|
| 280 | + */ |
|
| 281 | + public static function printAdminPage( $application, $name, $parameters = array() ) { |
|
| 282 | + $content = new OC_Template( $application, $name, "admin" ); |
|
| 283 | + foreach( $parameters as $key => $value ) { |
|
| 284 | + $content->assign( $key, $value ); |
|
| 285 | + } |
|
| 286 | + return $content->printPage(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Shortcut to print a simple page for guests |
|
| 291 | + * @param string $application The application we render the template for |
|
| 292 | + * @param string $name Name of the template |
|
| 293 | + * @param array|string $parameters Parameters for the template |
|
| 294 | + * @return bool |
|
| 295 | + */ |
|
| 296 | + public static function printGuestPage( $application, $name, $parameters = array() ) { |
|
| 297 | + $content = new OC_Template( $application, $name, "guest" ); |
|
| 298 | + foreach( $parameters as $key => $value ) { |
|
| 299 | + $content->assign( $key, $value ); |
|
| 300 | + } |
|
| 301 | + return $content->printPage(); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Print a fatal error page and terminates the script |
|
| 306 | + * @param string $error_msg The error message to show |
|
| 307 | + * @param string $hint An optional hint message - needs to be properly escaped |
|
| 308 | + */ |
|
| 309 | + public static function printErrorPage( $error_msg, $hint = '' ) { |
|
| 310 | + if ($error_msg === $hint) { |
|
| 311 | + // If the hint is the same as the message there is no need to display it twice. |
|
| 312 | + $hint = ''; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + try { |
|
| 316 | + $content = new \OC_Template( '', 'error', 'error', false ); |
|
| 317 | + $errors = array(array('error' => $error_msg, 'hint' => $hint)); |
|
| 318 | + $content->assign( 'errors', $errors ); |
|
| 319 | + $content->printPage(); |
|
| 320 | + } catch (\Exception $e) { |
|
| 321 | + $logger = \OC::$server->getLogger(); |
|
| 322 | + $logger->error("$error_msg $hint", ['app' => 'core']); |
|
| 323 | + $logger->logException($e, ['app' => 'core']); |
|
| 324 | + |
|
| 325 | + header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 326 | + header('Content-Type: text/plain; charset=utf-8'); |
|
| 327 | + print("$error_msg $hint"); |
|
| 328 | + } |
|
| 329 | + die(); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * print error page using Exception details |
|
| 334 | + * @param Exception | Throwable $exception |
|
| 335 | + */ |
|
| 336 | + public static function printExceptionErrorPage($exception, $fetchPage = false) { |
|
| 337 | + try { |
|
| 338 | + $request = \OC::$server->getRequest(); |
|
| 339 | + $content = new \OC_Template('', 'exception', 'error', false); |
|
| 340 | + $content->assign('errorClass', get_class($exception)); |
|
| 341 | + $content->assign('errorMsg', $exception->getMessage()); |
|
| 342 | + $content->assign('errorCode', $exception->getCode()); |
|
| 343 | + $content->assign('file', $exception->getFile()); |
|
| 344 | + $content->assign('line', $exception->getLine()); |
|
| 345 | + $content->assign('trace', $exception->getTraceAsString()); |
|
| 346 | + $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); |
|
| 347 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 348 | + $content->assign('requestID', $request->getId()); |
|
| 349 | + if ($fetchPage) { |
|
| 350 | + return $content->fetchPage(); |
|
| 351 | + } |
|
| 352 | + $content->printPage(); |
|
| 353 | + } catch (\Exception $e) { |
|
| 354 | + $logger = \OC::$server->getLogger(); |
|
| 355 | + $logger->logException($exception, ['app' => 'core']); |
|
| 356 | + $logger->logException($e, ['app' => 'core']); |
|
| 357 | + |
|
| 358 | + header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 359 | + header('Content-Type: text/plain; charset=utf-8'); |
|
| 360 | + print("Internal Server Error\n\n"); |
|
| 361 | + print("The server encountered an internal error and was unable to complete your request.\n"); |
|
| 362 | + print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
| 363 | + print("More details can be found in the server log.\n"); |
|
| 364 | + } |
|
| 365 | + die(); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * This is only here to reduce the dependencies in case of an exception to |
|
| 370 | + * still be able to print a plain error message. |
|
| 371 | + * |
|
| 372 | + * Returns the used HTTP protocol. |
|
| 373 | + * |
|
| 374 | + * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. |
|
| 375 | + * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead |
|
| 376 | + */ |
|
| 377 | + protected static function getHttpProtocol() { |
|
| 378 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 379 | + $validProtocols = [ |
|
| 380 | + 'HTTP/1.0', |
|
| 381 | + 'HTTP/1.1', |
|
| 382 | + 'HTTP/2', |
|
| 383 | + ]; |
|
| 384 | + if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 385 | + return $claimedProtocol; |
|
| 386 | + } |
|
| 387 | + return 'HTTP/1.1'; |
|
| 388 | + } |
|
| 389 | 389 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * "admin". |
| 70 | 70 | * @param bool $registerCall = true |
| 71 | 71 | */ |
| 72 | - public function __construct( $app, $name, $renderAs = "", $registerCall = true ) { |
|
| 72 | + public function __construct($app, $name, $renderAs = "", $registerCall = true) { |
|
| 73 | 73 | // Read the selected theme from the config file |
| 74 | 74 | self::initTemplateEngine($renderAs); |
| 75 | 75 | |
@@ -95,19 +95,19 @@ discard block |
||
| 95 | 95 | * @param string $renderAs |
| 96 | 96 | */ |
| 97 | 97 | public static function initTemplateEngine($renderAs) { |
| 98 | - if (self::$initTemplateEngineFirstRun){ |
|
| 98 | + if (self::$initTemplateEngineFirstRun) { |
|
| 99 | 99 | |
| 100 | 100 | //apps that started before the template initialization can load their own scripts/styles |
| 101 | 101 | //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true |
| 102 | 102 | //meaning the last script/style in this list will be loaded first |
| 103 | - if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
| 104 | - if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { |
|
| 105 | - OC_Util::addScript ( 'backgroundjobs', null, true ); |
|
| 103 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
| 104 | + if (\OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { |
|
| 105 | + OC_Util::addScript('backgroundjobs', null, true); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - OC_Util::addStyle('jquery-ui-fixes',null,true); |
|
| 110 | - OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true); |
|
| 109 | + OC_Util::addStyle('jquery-ui-fixes', null, true); |
|
| 110 | + OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui', null, true); |
|
| 111 | 111 | OC_Util::addStyle('server', null, true); |
| 112 | 112 | |
| 113 | 113 | // avatars |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | // Add the stuff we need always |
| 144 | 144 | // following logic will import all vendor libraries that are |
| 145 | 145 | // specified in core/js/core.json |
| 146 | - $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); |
|
| 147 | - if($fileContent !== false) { |
|
| 146 | + $fileContent = file_get_contents(OC::$SERVERROOT.'/core/js/core.json'); |
|
| 147 | + if ($fileContent !== false) { |
|
| 148 | 148 | $coreDependencies = json_decode($fileContent, true); |
| 149 | - foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
| 149 | + foreach (array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
| 150 | 150 | // remove trailing ".js" as addVendorScript will append it |
| 151 | 151 | OC_Util::addVendorScript( |
| 152 | - substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); |
|
| 152 | + substr($vendorLibrary, 0, strlen($vendorLibrary) - 3), null, true); |
|
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | throw new \Exception('Cannot read core/js/core.json'); |
@@ -180,12 +180,12 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | protected function findTemplate($theme, $app, $name) { |
| 182 | 182 | // Check if it is a app template or not. |
| 183 | - if( $app !== '' ) { |
|
| 183 | + if ($app !== '') { |
|
| 184 | 184 | $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app)); |
| 185 | 185 | } else { |
| 186 | 186 | $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT); |
| 187 | 187 | } |
| 188 | - $locator = new \OC\Template\TemplateFileLocator( $dirs ); |
|
| 188 | + $locator = new \OC\Template\TemplateFileLocator($dirs); |
|
| 189 | 189 | $template = $locator->find($name); |
| 190 | 190 | $path = $locator->getPath(); |
| 191 | 191 | return array($path, $template); |
@@ -198,8 +198,8 @@ discard block |
||
| 198 | 198 | * @param string $text the text content for the element. If $text is null then the |
| 199 | 199 | * element will be written as empty element. So use "" to get a closing tag. |
| 200 | 200 | */ |
| 201 | - public function addHeader($tag, $attributes, $text=null) { |
|
| 202 | - $this->headers[]= array( |
|
| 201 | + public function addHeader($tag, $attributes, $text = null) { |
|
| 202 | + $this->headers[] = array( |
|
| 203 | 203 | 'tag' => $tag, |
| 204 | 204 | 'attributes' => $attributes, |
| 205 | 205 | 'text' => $text |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | public function fetchPage($additionalParams = null) { |
| 217 | 217 | $data = parent::fetchPage($additionalParams); |
| 218 | 218 | |
| 219 | - if( $this->renderAs ) { |
|
| 219 | + if ($this->renderAs) { |
|
| 220 | 220 | $page = new TemplateLayout($this->renderAs, $this->app); |
| 221 | 221 | |
| 222 | 222 | // Add custom headers |
| 223 | 223 | $headers = ''; |
| 224 | - foreach(OC_Util::$headers as $header) { |
|
| 224 | + foreach (OC_Util::$headers as $header) { |
|
| 225 | 225 | $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); |
| 226 | - foreach($header['attributes'] as $name=>$value) { |
|
| 226 | + foreach ($header['attributes'] as $name=>$value) { |
|
| 227 | 227 | $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; |
| 228 | 228 | } |
| 229 | 229 | if ($header['text'] !== null) { |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * Includes another template. use <?php echo $this->inc('template'); ?> to |
| 253 | 253 | * do this. |
| 254 | 254 | */ |
| 255 | - public function inc( $file, $additionalParams = null ) { |
|
| 255 | + public function inc($file, $additionalParams = null) { |
|
| 256 | 256 | return $this->load($this->path.$file.'.php', $additionalParams); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | * @param array $parameters Parameters for the template |
| 264 | 264 | * @return boolean|null |
| 265 | 265 | */ |
| 266 | - public static function printUserPage( $application, $name, $parameters = array() ) { |
|
| 267 | - $content = new OC_Template( $application, $name, "user" ); |
|
| 268 | - foreach( $parameters as $key => $value ) { |
|
| 269 | - $content->assign( $key, $value ); |
|
| 266 | + public static function printUserPage($application, $name, $parameters = array()) { |
|
| 267 | + $content = new OC_Template($application, $name, "user"); |
|
| 268 | + foreach ($parameters as $key => $value) { |
|
| 269 | + $content->assign($key, $value); |
|
| 270 | 270 | } |
| 271 | 271 | print $content->printPage(); |
| 272 | 272 | } |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | * @param array $parameters Parameters for the template |
| 279 | 279 | * @return bool |
| 280 | 280 | */ |
| 281 | - public static function printAdminPage( $application, $name, $parameters = array() ) { |
|
| 282 | - $content = new OC_Template( $application, $name, "admin" ); |
|
| 283 | - foreach( $parameters as $key => $value ) { |
|
| 284 | - $content->assign( $key, $value ); |
|
| 281 | + public static function printAdminPage($application, $name, $parameters = array()) { |
|
| 282 | + $content = new OC_Template($application, $name, "admin"); |
|
| 283 | + foreach ($parameters as $key => $value) { |
|
| 284 | + $content->assign($key, $value); |
|
| 285 | 285 | } |
| 286 | 286 | return $content->printPage(); |
| 287 | 287 | } |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | * @param array|string $parameters Parameters for the template |
| 294 | 294 | * @return bool |
| 295 | 295 | */ |
| 296 | - public static function printGuestPage( $application, $name, $parameters = array() ) { |
|
| 297 | - $content = new OC_Template( $application, $name, "guest" ); |
|
| 298 | - foreach( $parameters as $key => $value ) { |
|
| 299 | - $content->assign( $key, $value ); |
|
| 296 | + public static function printGuestPage($application, $name, $parameters = array()) { |
|
| 297 | + $content = new OC_Template($application, $name, "guest"); |
|
| 298 | + foreach ($parameters as $key => $value) { |
|
| 299 | + $content->assign($key, $value); |
|
| 300 | 300 | } |
| 301 | 301 | return $content->printPage(); |
| 302 | 302 | } |
@@ -306,23 +306,23 @@ discard block |
||
| 306 | 306 | * @param string $error_msg The error message to show |
| 307 | 307 | * @param string $hint An optional hint message - needs to be properly escaped |
| 308 | 308 | */ |
| 309 | - public static function printErrorPage( $error_msg, $hint = '' ) { |
|
| 309 | + public static function printErrorPage($error_msg, $hint = '') { |
|
| 310 | 310 | if ($error_msg === $hint) { |
| 311 | 311 | // If the hint is the same as the message there is no need to display it twice. |
| 312 | 312 | $hint = ''; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | try { |
| 316 | - $content = new \OC_Template( '', 'error', 'error', false ); |
|
| 316 | + $content = new \OC_Template('', 'error', 'error', false); |
|
| 317 | 317 | $errors = array(array('error' => $error_msg, 'hint' => $hint)); |
| 318 | - $content->assign( 'errors', $errors ); |
|
| 318 | + $content->assign('errors', $errors); |
|
| 319 | 319 | $content->printPage(); |
| 320 | 320 | } catch (\Exception $e) { |
| 321 | 321 | $logger = \OC::$server->getLogger(); |
| 322 | 322 | $logger->error("$error_msg $hint", ['app' => 'core']); |
| 323 | 323 | $logger->logException($e, ['app' => 'core']); |
| 324 | 324 | |
| 325 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 325 | + header(self::getHttpProtocol().' 500 Internal Server Error'); |
|
| 326 | 326 | header('Content-Type: text/plain; charset=utf-8'); |
| 327 | 327 | print("$error_msg $hint"); |
| 328 | 328 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | $logger->logException($exception, ['app' => 'core']); |
| 356 | 356 | $logger->logException($e, ['app' => 'core']); |
| 357 | 357 | |
| 358 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
| 358 | + header(self::getHttpProtocol().' 500 Internal Server Error'); |
|
| 359 | 359 | header('Content-Type: text/plain; charset=utf-8'); |
| 360 | 360 | print("Internal Server Error\n\n"); |
| 361 | 361 | print("The server encountered an internal error and was unable to complete your request.\n"); |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | 'HTTP/1.1', |
| 382 | 382 | 'HTTP/2', |
| 383 | 383 | ]; |
| 384 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 384 | + if (in_array($claimedProtocol, $validProtocols, true)) { |
|
| 385 | 385 | return $claimedProtocol; |
| 386 | 386 | } |
| 387 | 387 | return 'HTTP/1.1'; |
@@ -49,238 +49,238 @@ |
||
| 49 | 49 | * @package OCA\Files\Controller |
| 50 | 50 | */ |
| 51 | 51 | class ViewController extends Controller { |
| 52 | - /** @var string */ |
|
| 53 | - protected $appName; |
|
| 54 | - /** @var IRequest */ |
|
| 55 | - protected $request; |
|
| 56 | - /** @var IURLGenerator */ |
|
| 57 | - protected $urlGenerator; |
|
| 58 | - /** @var IL10N */ |
|
| 59 | - protected $l10n; |
|
| 60 | - /** @var IConfig */ |
|
| 61 | - protected $config; |
|
| 62 | - /** @var EventDispatcherInterface */ |
|
| 63 | - protected $eventDispatcher; |
|
| 64 | - /** @var IUserSession */ |
|
| 65 | - protected $userSession; |
|
| 66 | - /** @var IAppManager */ |
|
| 67 | - protected $appManager; |
|
| 68 | - /** @var IRootFolder */ |
|
| 69 | - protected $rootFolder; |
|
| 52 | + /** @var string */ |
|
| 53 | + protected $appName; |
|
| 54 | + /** @var IRequest */ |
|
| 55 | + protected $request; |
|
| 56 | + /** @var IURLGenerator */ |
|
| 57 | + protected $urlGenerator; |
|
| 58 | + /** @var IL10N */ |
|
| 59 | + protected $l10n; |
|
| 60 | + /** @var IConfig */ |
|
| 61 | + protected $config; |
|
| 62 | + /** @var EventDispatcherInterface */ |
|
| 63 | + protected $eventDispatcher; |
|
| 64 | + /** @var IUserSession */ |
|
| 65 | + protected $userSession; |
|
| 66 | + /** @var IAppManager */ |
|
| 67 | + protected $appManager; |
|
| 68 | + /** @var IRootFolder */ |
|
| 69 | + protected $rootFolder; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $appName |
|
| 73 | - * @param IRequest $request |
|
| 74 | - * @param IURLGenerator $urlGenerator |
|
| 75 | - * @param IL10N $l10n |
|
| 76 | - * @param IConfig $config |
|
| 77 | - * @param EventDispatcherInterface $eventDispatcherInterface |
|
| 78 | - * @param IUserSession $userSession |
|
| 79 | - * @param IAppManager $appManager |
|
| 80 | - * @param IRootFolder $rootFolder |
|
| 81 | - */ |
|
| 82 | - public function __construct($appName, |
|
| 83 | - IRequest $request, |
|
| 84 | - IURLGenerator $urlGenerator, |
|
| 85 | - IL10N $l10n, |
|
| 86 | - IConfig $config, |
|
| 87 | - EventDispatcherInterface $eventDispatcherInterface, |
|
| 88 | - IUserSession $userSession, |
|
| 89 | - IAppManager $appManager, |
|
| 90 | - IRootFolder $rootFolder |
|
| 91 | - ) { |
|
| 92 | - parent::__construct($appName, $request); |
|
| 93 | - $this->appName = $appName; |
|
| 94 | - $this->request = $request; |
|
| 95 | - $this->urlGenerator = $urlGenerator; |
|
| 96 | - $this->l10n = $l10n; |
|
| 97 | - $this->config = $config; |
|
| 98 | - $this->eventDispatcher = $eventDispatcherInterface; |
|
| 99 | - $this->userSession = $userSession; |
|
| 100 | - $this->appManager = $appManager; |
|
| 101 | - $this->rootFolder = $rootFolder; |
|
| 102 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $appName |
|
| 73 | + * @param IRequest $request |
|
| 74 | + * @param IURLGenerator $urlGenerator |
|
| 75 | + * @param IL10N $l10n |
|
| 76 | + * @param IConfig $config |
|
| 77 | + * @param EventDispatcherInterface $eventDispatcherInterface |
|
| 78 | + * @param IUserSession $userSession |
|
| 79 | + * @param IAppManager $appManager |
|
| 80 | + * @param IRootFolder $rootFolder |
|
| 81 | + */ |
|
| 82 | + public function __construct($appName, |
|
| 83 | + IRequest $request, |
|
| 84 | + IURLGenerator $urlGenerator, |
|
| 85 | + IL10N $l10n, |
|
| 86 | + IConfig $config, |
|
| 87 | + EventDispatcherInterface $eventDispatcherInterface, |
|
| 88 | + IUserSession $userSession, |
|
| 89 | + IAppManager $appManager, |
|
| 90 | + IRootFolder $rootFolder |
|
| 91 | + ) { |
|
| 92 | + parent::__construct($appName, $request); |
|
| 93 | + $this->appName = $appName; |
|
| 94 | + $this->request = $request; |
|
| 95 | + $this->urlGenerator = $urlGenerator; |
|
| 96 | + $this->l10n = $l10n; |
|
| 97 | + $this->config = $config; |
|
| 98 | + $this->eventDispatcher = $eventDispatcherInterface; |
|
| 99 | + $this->userSession = $userSession; |
|
| 100 | + $this->appManager = $appManager; |
|
| 101 | + $this->rootFolder = $rootFolder; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * @param string $appName |
|
| 106 | - * @param string $scriptName |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - protected function renderScript($appName, $scriptName) { |
|
| 110 | - $content = ''; |
|
| 111 | - $appPath = \OC_App::getAppPath($appName); |
|
| 112 | - $scriptPath = $appPath . '/' . $scriptName; |
|
| 113 | - if (file_exists($scriptPath)) { |
|
| 114 | - // TODO: sanitize path / script name ? |
|
| 115 | - ob_start(); |
|
| 116 | - include $scriptPath; |
|
| 117 | - $content = ob_get_contents(); |
|
| 118 | - @ob_end_clean(); |
|
| 119 | - } |
|
| 120 | - return $content; |
|
| 121 | - } |
|
| 104 | + /** |
|
| 105 | + * @param string $appName |
|
| 106 | + * @param string $scriptName |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + protected function renderScript($appName, $scriptName) { |
|
| 110 | + $content = ''; |
|
| 111 | + $appPath = \OC_App::getAppPath($appName); |
|
| 112 | + $scriptPath = $appPath . '/' . $scriptName; |
|
| 113 | + if (file_exists($scriptPath)) { |
|
| 114 | + // TODO: sanitize path / script name ? |
|
| 115 | + ob_start(); |
|
| 116 | + include $scriptPath; |
|
| 117 | + $content = ob_get_contents(); |
|
| 118 | + @ob_end_clean(); |
|
| 119 | + } |
|
| 120 | + return $content; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * FIXME: Replace with non static code |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - * @throws \OCP\Files\NotFoundException |
|
| 128 | - */ |
|
| 129 | - protected function getStorageInfo() { |
|
| 130 | - $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 131 | - return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 132 | - } |
|
| 123 | + /** |
|
| 124 | + * FIXME: Replace with non static code |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + * @throws \OCP\Files\NotFoundException |
|
| 128 | + */ |
|
| 129 | + protected function getStorageInfo() { |
|
| 130 | + $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false); |
|
| 131 | + return \OC_Helper::getStorageInfo('/', $dirInfo); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * @NoCSRFRequired |
|
| 136 | - * @NoAdminRequired |
|
| 137 | - * |
|
| 138 | - * @param string $dir |
|
| 139 | - * @param string $view |
|
| 140 | - * @param string $fileid |
|
| 141 | - * @return TemplateResponse|RedirectResponse |
|
| 142 | - */ |
|
| 143 | - public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 144 | - if ($fileid !== null) { |
|
| 145 | - try { |
|
| 146 | - return $this->showFile($fileid); |
|
| 147 | - } catch (NotFoundException $e) { |
|
| 148 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 149 | - } |
|
| 150 | - } |
|
| 134 | + /** |
|
| 135 | + * @NoCSRFRequired |
|
| 136 | + * @NoAdminRequired |
|
| 137 | + * |
|
| 138 | + * @param string $dir |
|
| 139 | + * @param string $view |
|
| 140 | + * @param string $fileid |
|
| 141 | + * @return TemplateResponse|RedirectResponse |
|
| 142 | + */ |
|
| 143 | + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { |
|
| 144 | + if ($fileid !== null) { |
|
| 145 | + try { |
|
| 146 | + return $this->showFile($fileid); |
|
| 147 | + } catch (NotFoundException $e) { |
|
| 148 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 152 | + $nav = new \OCP\Template('files', 'appnavigation', ''); |
|
| 153 | 153 | |
| 154 | - // Load the files we need |
|
| 155 | - \OCP\Util::addScript('files', 'app'); |
|
| 156 | - \OCP\Util::addScript('files', 'file-upload'); |
|
| 157 | - \OCP\Util::addScript('files', 'newfilemenu'); |
|
| 158 | - \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
| 159 | - \OCP\Util::addScript('files', 'jquery-visibility'); |
|
| 160 | - \OCP\Util::addScript('files', 'fileinfomodel'); |
|
| 161 | - \OCP\Util::addScript('files', 'filesummary'); |
|
| 162 | - \OCP\Util::addScript('files', 'breadcrumb'); |
|
| 163 | - \OCP\Util::addScript('files', 'filelist'); |
|
| 164 | - \OCP\Util::addScript('files', 'search'); |
|
| 154 | + // Load the files we need |
|
| 155 | + \OCP\Util::addScript('files', 'app'); |
|
| 156 | + \OCP\Util::addScript('files', 'file-upload'); |
|
| 157 | + \OCP\Util::addScript('files', 'newfilemenu'); |
|
| 158 | + \OCP\Util::addScript('files', 'jquery.fileupload'); |
|
| 159 | + \OCP\Util::addScript('files', 'jquery-visibility'); |
|
| 160 | + \OCP\Util::addScript('files', 'fileinfomodel'); |
|
| 161 | + \OCP\Util::addScript('files', 'filesummary'); |
|
| 162 | + \OCP\Util::addScript('files', 'breadcrumb'); |
|
| 163 | + \OCP\Util::addScript('files', 'filelist'); |
|
| 164 | + \OCP\Util::addScript('files', 'search'); |
|
| 165 | 165 | |
| 166 | - \OCP\Util::addScript('files', 'favoritesfilelist'); |
|
| 167 | - \OCP\Util::addScript('files', 'recentfilelist'); |
|
| 168 | - \OCP\Util::addScript('files', 'tagsplugin'); |
|
| 169 | - \OCP\Util::addScript('files', 'gotoplugin'); |
|
| 170 | - \OCP\Util::addScript('files', 'favoritesplugin'); |
|
| 171 | - \OCP\Util::addScript('files', 'recentplugin'); |
|
| 166 | + \OCP\Util::addScript('files', 'favoritesfilelist'); |
|
| 167 | + \OCP\Util::addScript('files', 'recentfilelist'); |
|
| 168 | + \OCP\Util::addScript('files', 'tagsplugin'); |
|
| 169 | + \OCP\Util::addScript('files', 'gotoplugin'); |
|
| 170 | + \OCP\Util::addScript('files', 'favoritesplugin'); |
|
| 171 | + \OCP\Util::addScript('files', 'recentplugin'); |
|
| 172 | 172 | |
| 173 | - \OCP\Util::addScript('files', 'detailfileinfoview'); |
|
| 174 | - \OCP\Util::addScript('files', 'sidebarpreviewmanager'); |
|
| 175 | - \OCP\Util::addScript('files', 'sidebarpreviewtext'); |
|
| 176 | - \OCP\Util::addScript('files', 'detailtabview'); |
|
| 177 | - \OCP\Util::addScript('files', 'mainfileinfodetailview'); |
|
| 178 | - \OCP\Util::addScript('files', 'detailsview'); |
|
| 179 | - \OCP\Util::addStyle('files', 'merged'); |
|
| 173 | + \OCP\Util::addScript('files', 'detailfileinfoview'); |
|
| 174 | + \OCP\Util::addScript('files', 'sidebarpreviewmanager'); |
|
| 175 | + \OCP\Util::addScript('files', 'sidebarpreviewtext'); |
|
| 176 | + \OCP\Util::addScript('files', 'detailtabview'); |
|
| 177 | + \OCP\Util::addScript('files', 'mainfileinfodetailview'); |
|
| 178 | + \OCP\Util::addScript('files', 'detailsview'); |
|
| 179 | + \OCP\Util::addStyle('files', 'merged'); |
|
| 180 | 180 | |
| 181 | - \OC_Util::addVendorScript('core', 'handlebars/handlebars'); |
|
| 181 | + \OC_Util::addVendorScript('core', 'handlebars/handlebars'); |
|
| 182 | 182 | |
| 183 | - \OCP\Util::addScript('files', 'fileactions'); |
|
| 184 | - \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
| 185 | - \OCP\Util::addScript('files', 'files'); |
|
| 186 | - \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
| 187 | - \OCP\Util::addScript('files', 'navigation'); |
|
| 183 | + \OCP\Util::addScript('files', 'fileactions'); |
|
| 184 | + \OCP\Util::addScript('files', 'fileactionsmenu'); |
|
| 185 | + \OCP\Util::addScript('files', 'files'); |
|
| 186 | + \OCP\Util::addScript('files', 'keyboardshortcuts'); |
|
| 187 | + \OCP\Util::addScript('files', 'navigation'); |
|
| 188 | 188 | |
| 189 | - // mostly for the home storage's free space |
|
| 190 | - // FIXME: Make non static |
|
| 191 | - $storageInfo = $this->getStorageInfo(); |
|
| 189 | + // mostly for the home storage's free space |
|
| 190 | + // FIXME: Make non static |
|
| 191 | + $storageInfo = $this->getStorageInfo(); |
|
| 192 | 192 | |
| 193 | - \OCA\Files\App::getNavigationManager()->add( |
|
| 194 | - [ |
|
| 195 | - 'id' => 'favorites', |
|
| 196 | - 'appname' => 'files', |
|
| 197 | - 'script' => 'simplelist.php', |
|
| 198 | - 'order' => 5, |
|
| 199 | - 'name' => $this->l10n->t('Favorites') |
|
| 200 | - ] |
|
| 201 | - ); |
|
| 193 | + \OCA\Files\App::getNavigationManager()->add( |
|
| 194 | + [ |
|
| 195 | + 'id' => 'favorites', |
|
| 196 | + 'appname' => 'files', |
|
| 197 | + 'script' => 'simplelist.php', |
|
| 198 | + 'order' => 5, |
|
| 199 | + 'name' => $this->l10n->t('Favorites') |
|
| 200 | + ] |
|
| 201 | + ); |
|
| 202 | 202 | |
| 203 | - $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 204 | - usort($navItems, function($item1, $item2) { |
|
| 205 | - return $item1['order'] - $item2['order']; |
|
| 206 | - }); |
|
| 207 | - $nav->assign('navigationItems', $navItems); |
|
| 203 | + $navItems = \OCA\Files\App::getNavigationManager()->getAll(); |
|
| 204 | + usort($navItems, function($item1, $item2) { |
|
| 205 | + return $item1['order'] - $item2['order']; |
|
| 206 | + }); |
|
| 207 | + $nav->assign('navigationItems', $navItems); |
|
| 208 | 208 | |
| 209 | - $contentItems = []; |
|
| 209 | + $contentItems = []; |
|
| 210 | 210 | |
| 211 | - // render the container content for every navigation item |
|
| 212 | - foreach ($navItems as $item) { |
|
| 213 | - $content = ''; |
|
| 214 | - if (isset($item['script'])) { |
|
| 215 | - $content = $this->renderScript($item['appname'], $item['script']); |
|
| 216 | - } |
|
| 217 | - $contentItem = []; |
|
| 218 | - $contentItem['id'] = $item['id']; |
|
| 219 | - $contentItem['content'] = $content; |
|
| 220 | - $contentItems[] = $contentItem; |
|
| 221 | - } |
|
| 211 | + // render the container content for every navigation item |
|
| 212 | + foreach ($navItems as $item) { |
|
| 213 | + $content = ''; |
|
| 214 | + if (isset($item['script'])) { |
|
| 215 | + $content = $this->renderScript($item['appname'], $item['script']); |
|
| 216 | + } |
|
| 217 | + $contentItem = []; |
|
| 218 | + $contentItem['id'] = $item['id']; |
|
| 219 | + $contentItem['content'] = $content; |
|
| 220 | + $contentItems[] = $contentItem; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
| 223 | + $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts'); |
|
| 224 | 224 | |
| 225 | - $params = []; |
|
| 226 | - $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
| 227 | - $params['owner'] = $storageInfo['owner']; |
|
| 228 | - $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
| 229 | - $params['isPublic'] = false; |
|
| 230 | - $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 231 | - $user = $this->userSession->getUser()->getUID(); |
|
| 232 | - $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 233 | - $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 234 | - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 235 | - $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 236 | - $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 237 | - $params['appNavigation'] = $nav; |
|
| 238 | - $params['appContents'] = $contentItems; |
|
| 225 | + $params = []; |
|
| 226 | + $params['usedSpacePercent'] = (int)$storageInfo['relative']; |
|
| 227 | + $params['owner'] = $storageInfo['owner']; |
|
| 228 | + $params['ownerDisplayName'] = $storageInfo['ownerDisplayName']; |
|
| 229 | + $params['isPublic'] = false; |
|
| 230 | + $params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'); |
|
| 231 | + $user = $this->userSession->getUser()->getUID(); |
|
| 232 | + $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); |
|
| 233 | + $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); |
|
| 234 | + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); |
|
| 235 | + $params['showHiddenFiles'] = $showHidden ? 1 : 0; |
|
| 236 | + $params['fileNotFound'] = $fileNotFound ? 1 : 0; |
|
| 237 | + $params['appNavigation'] = $nav; |
|
| 238 | + $params['appContents'] = $contentItems; |
|
| 239 | 239 | |
| 240 | - $response = new TemplateResponse( |
|
| 241 | - $this->appName, |
|
| 242 | - 'index', |
|
| 243 | - $params |
|
| 244 | - ); |
|
| 245 | - $policy = new ContentSecurityPolicy(); |
|
| 246 | - $policy->addAllowedFrameDomain('\'self\''); |
|
| 247 | - $response->setContentSecurityPolicy($policy); |
|
| 240 | + $response = new TemplateResponse( |
|
| 241 | + $this->appName, |
|
| 242 | + 'index', |
|
| 243 | + $params |
|
| 244 | + ); |
|
| 245 | + $policy = new ContentSecurityPolicy(); |
|
| 246 | + $policy->addAllowedFrameDomain('\'self\''); |
|
| 247 | + $response->setContentSecurityPolicy($policy); |
|
| 248 | 248 | |
| 249 | - return $response; |
|
| 250 | - } |
|
| 249 | + return $response; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Redirects to the file list and highlight the given file id |
|
| 254 | - * |
|
| 255 | - * @param string $fileId file id to show |
|
| 256 | - * @return RedirectResponse redirect response or not found response |
|
| 257 | - * @throws \OCP\Files\NotFoundException |
|
| 258 | - */ |
|
| 259 | - private function showFile($fileId) { |
|
| 260 | - $uid = $this->userSession->getUser()->getUID(); |
|
| 261 | - $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 262 | - $files = $baseFolder->getById($fileId); |
|
| 263 | - $params = []; |
|
| 252 | + /** |
|
| 253 | + * Redirects to the file list and highlight the given file id |
|
| 254 | + * |
|
| 255 | + * @param string $fileId file id to show |
|
| 256 | + * @return RedirectResponse redirect response or not found response |
|
| 257 | + * @throws \OCP\Files\NotFoundException |
|
| 258 | + */ |
|
| 259 | + private function showFile($fileId) { |
|
| 260 | + $uid = $this->userSession->getUser()->getUID(); |
|
| 261 | + $baseFolder = $this->rootFolder->getUserFolder($uid); |
|
| 262 | + $files = $baseFolder->getById($fileId); |
|
| 263 | + $params = []; |
|
| 264 | 264 | |
| 265 | - if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 266 | - $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 267 | - $files = $baseFolder->getById($fileId); |
|
| 268 | - $params['view'] = 'trashbin'; |
|
| 269 | - } |
|
| 265 | + if (empty($files) && $this->appManager->isEnabledForUser('files_trashbin')) { |
|
| 266 | + $baseFolder = $this->rootFolder->get($uid . '/files_trashbin/files/'); |
|
| 267 | + $files = $baseFolder->getById($fileId); |
|
| 268 | + $params['view'] = 'trashbin'; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - if (!empty($files)) { |
|
| 272 | - $file = current($files); |
|
| 273 | - if ($file instanceof Folder) { |
|
| 274 | - // set the full path to enter the folder |
|
| 275 | - $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 276 | - } else { |
|
| 277 | - // set parent path as dir |
|
| 278 | - $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 279 | - // and scroll to the entry |
|
| 280 | - $params['scrollto'] = $file->getName(); |
|
| 281 | - } |
|
| 282 | - return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 283 | - } |
|
| 284 | - throw new \OCP\Files\NotFoundException(); |
|
| 285 | - } |
|
| 271 | + if (!empty($files)) { |
|
| 272 | + $file = current($files); |
|
| 273 | + if ($file instanceof Folder) { |
|
| 274 | + // set the full path to enter the folder |
|
| 275 | + $params['dir'] = $baseFolder->getRelativePath($file->getPath()); |
|
| 276 | + } else { |
|
| 277 | + // set parent path as dir |
|
| 278 | + $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath()); |
|
| 279 | + // and scroll to the entry |
|
| 280 | + $params['scrollto'] = $file->getName(); |
|
| 281 | + } |
|
| 282 | + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); |
|
| 283 | + } |
|
| 284 | + throw new \OCP\Files\NotFoundException(); |
|
| 285 | + } |
|
| 286 | 286 | } |