/** * Include all JavaScript files matching the include regular expression * and not matching the exclude regular expression. * * @param string $include Regular expression of files to include * @param string $exclude Regular expression of files to exclude * @param string $package The package key of the resources to include or current controller package if NULL * @param string $subpackage The subpackage key of the resources to include or current controller subpackage if NULL * @param string $directory The directory inside the current subpackage. By default, the "JavaScript" directory will be used. * @return string */ public function render($include, $exclude = NULL, $package = NULL, $subpackage = NULL, $directory = 'JavaScript') { $packageKey = $package === NULL ? $this->controllerContext->getRequest()->getControllerPackageKey() : $package; $subpackageKey = $subpackage === NULL ? $this->controllerContext->getRequest()->getControllerSubpackageKey() : $subpackage; $baseDirectory = 'resource://' . $packageKey . '/Public/' . ($subpackageKey !== NULL ? $subpackageKey . '/' : '') . $directory . '/'; $staticJavaScriptWebBaseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/' . $packageKey . '/' . ($subpackageKey !== NULL ? $subpackageKey . '/' : '') . $directory . '/'; $iterator = $this->iterateDirectoryRecursively($baseDirectory); if ($iterator === NULL) { return '<!-- Warning: Cannot include JavaScript because directory "' . $baseDirectory . '" does not exist. -->'; } $uris = array(); foreach ($iterator as $file) { $relativePath = substr($file->getPathname(), strlen($baseDirectory)); $relativePath = \TYPO3\Flow\Utility\Files::getUnixStylePath($relativePath); if (!$this->patternMatchesPath($exclude, $relativePath) && $this->patternMatchesPath($include, $relativePath)) { $uris[] = $staticJavaScriptWebBaseUri . $relativePath; } } // Sadly, the aloha editor needs a predefined inclusion order, which right now matches // the sorted URI list. that's why we sort here... asort($uris); $output = ''; foreach ($uris as $uri) { $output .= '<script src="' . $uri . '"></script>' . chr(10); } return $output; }
/** * Returns the HTML needed to include ExtJS, that is, CSS and JS includes. * * = Examples = * * <code title="Simple"> * {namespace ext=TYPO3\ExtJS\ViewHelpers} * ... * <ext:include/> * </code> * Renders the script and link tags needed to include everything needed to * use ExtJS. * * <code title="Use a specific theme"> * <ext:include theme="xtheme-gray"/> * </code> * * @param string $theme The theme to include, simply the name of the CSS * @param boolean $debug Whether to use the debug version of ExtJS * @param boolean $includeStylesheets Include ExtJS CSS files if true * @return string HTML needed to include ExtJS * @api */ public function render($theme = 'xtheme-blue', $debug = NULL, $includeStylesheets = TRUE) { if ($debug === NULL) { $debug = $this->objectManager->getContext()->isDevelopment() ?: FALSE; } $baseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/TYPO3.ExtJS/'; $output = ''; if ($includeStylesheets) { $output .= ' <link rel="stylesheet" href="' . $baseUri . 'CSS/ext-all-notheme.css" /> <link rel="stylesheet" href="' . $baseUri . 'CSS/' . $theme . '.css" />'; } if ($debug) { $output .= ' <script type="text/javascript" src="' . $baseUri . 'JavaScript/adapter/ext/ext-base-debug.js"></script> <script type="text/javascript" src="' . $baseUri . 'JavaScript/ext-all-debug.js"></script>'; } else { $output .= ' <script type="text/javascript" src="' . $baseUri . 'JavaScript/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="' . $baseUri . 'JavaScript/ext-all.js"></script>'; } $output .= ' <script type="text/javascript"> Ext.BLANK_IMAGE_URL = \'' . $baseUri . 'images/default/s.gif\'; Ext.FlashComponent.EXPRESS_INSTALL_URL = \'' . $baseUri . 'Flash/expressinstall.swf\'; Ext.chart.Chart.CHART_URL = \'' . $baseUri . 'Flash/chart.swf\'; </script> '; return $output; }
/** * Returns the HTML needed to include the ExtJS ux class. * * = Examples = * * <code title="Simple"> * {namespace ext=TYPO3\ExtJS\ViewHelpers} * ... * <ext:ux name="StatusBar"/> * </code> * Renders the script tag to include the StatusBar ux class. * * @param string $name The name of the ux class * @return string HTML needed to include ExtJS * @api */ public function render($name) { $baseUri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/TYPO3.ExtJS/'; return ' <script type="text/javascript" src="' . $baseUri . 'JavaScript/ux/' . $name . '.js"></script> '; }
/** * @param string $version * @param boolean $loadJQuery * @param boolean $loadEmberData * @param boolean $minified * @return string * @throws \Exception */ public function render($version = NULL, $loadJQuery = FALSE, $loadEmberData = FALSE, $minified = TRUE) { $defaults = $this->getConfigurationArray('defaults', $version, $minified); $version = $this->findVersionToLoad($version); // Make sure the requested version has Ember-data configured if ($loadEmberData && $this->settings['versions'][$version]['hasData'] === FALSE) { throw new \Exception(sprintf('Version %s has no Ember-data configured', $version)); } // Merge defaults and version configuration (version configuration overrides defaults) $configuration = Arrays::arrayMergeRecursiveOverrule($defaults, $this->getConfigurationArray($version, $version, $minified), FALSE, FALSE); // Remove jQuery if ($loadJQuery === FALSE && isset($configuration['requirements']['jquery'])) { unset($configuration['requirements']['jquery']); } // Build the includes array $includes = array(); foreach ($configuration['requirements'] as $requirement) { $includes[] = $requirement['path']; } $includes[] = $this->getResourcePath($this->settings['paths']['ember'], $version, $minified); if ($loadEmberData === TRUE) { $includes[] = $this->getResourcePath($this->settings['paths']['ember-data'], $version, $minified); } // Generate script tags $baseUrl = $this->resourcePublisher->getStaticResourcesWebBaseUri(); $includes = array_map(function ($file) use($baseUrl) { return sprintf('<script src="%sPackages/%s"></script>', $baseUrl, $file); }, $includes); return implode('', $includes); }
/** * @param string $resourcePath * @return string * @throws ViewHelperException */ protected function resolveResourcePath($resourcePath) { // TODO: This method should be somewhere in the resource manager probably? $matches = array(); preg_match('#resource://([^/]*)/Public/(.*)#', $resourcePath, $matches); if ($matches === array()) { throw new ViewHelperException('Resource path "' . $resourcePath . '" can\'t be resolved.', 1328543327); } $package = $matches[1]; $path = $matches[2]; return $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/' . $package . '/' . $path; }
/** * Render the URI to the resource. The filename is used from child content. * * @param string $path The location of the resource, can be either a path relative to the Public resource directory of the package or a resource://... URI * @param string $package Target package key. If not set, the current package key will be used * @param Resource $resource If specified, this resource object is used instead of the path and package information * @param boolean $localize Whether resource localization should be attempted or not * @return string The absolute URI to the resource * @throws InvalidVariableException * @api */ public function render($path = NULL, $package = NULL, Resource $resource = NULL, $localize = TRUE) { if ($resource !== NULL) { $uri = $this->resourcePublisher->getPersistentResourceWebUri($resource); if ($uri === FALSE) { $uri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'BrokenResource'; } } else { if ($path === NULL) { throw new InvalidVariableException('The ResourceViewHelper did neither contain a valuable "resource" nor "path" argument.', 1353512742); } if ($package === NULL) { $package = $this->controllerContext->getRequest()->getControllerPackageKey(); } if (strpos($path, 'resource://') === 0) { $matches = array(); if (preg_match('#^resource://([^/]+)/Public/(.*)#', $path, $matches) === 1) { $package = $matches[1]; $path = $matches[2]; } else { throw new InvalidVariableException(sprintf('The path "%s" which was given to the ResourceViewHelper must point to a public resource.', $path), 1353512639); } } if ($localize === TRUE) { $resourcePath = 'resource://' . $package . '/Public/' . $path; $localizedResourcePathData = $this->i18nService->getLocalizedFilename($resourcePath); $matches = array(); if (preg_match('#resource://([^/]+)/Public/(.*)#', current($localizedResourcePathData), $matches) === 1) { $package = $matches[1]; $path = $matches[2]; } } $uri = $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/' . $package . '/' . $path; } return $uri; }