public function render_file($filename, $extension)
 {
     $img = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'pjpeg'];
     $path = $this->uploads_directory_name . '/' . $filename;
     if (in_array($extension, $img)) {
         return '<img src="' . $this->packages->getUrl($path) . '" height="42">';
     }
     return '<a href="' . $this->packages->getUrl($path) . '" download><i class="fa fa-download"></i></a>';
 }
Esempio n. 2
0
 /**
  * Returns the public url/path of an asset.
  *
  * @param string $path
  *
  * @return string
  */
 public function handle($path)
 {
     // getFile first to split mount point from path, if present.
     $file = $this->filesystem->getFile($path);
     if ($this->packages instanceof Packages) {
         return $this->packages->getUrl($file->getPath(), $file->getMountPoint());
     }
     return $this->packages->getUrl($file->getPath());
 }
 public function initLogger()
 {
     if (false === $this->isEnabled) {
         return '';
     }
     $backendUrl = addslashes($this->router->generate(self::ROUTE));
     $scriptUrl = $this->packages->getUrl(self::ASSET_PATH);
     $allowedLevels = empty($this->allowedLevels) ? '' : ' data-allowed-levels="' . implode(',', $this->allowedLevels) . '"';
     return '<script src="' . $scriptUrl . '" data-backend-url="' . $backendUrl . '"' . $allowedLevels . '></script>';
 }
Esempio n. 4
0
 /**
  * WebComponentService constructor.
  * @param ContainerInterface $container
  * @param Packages $packages
  * @param string $pathLib
  * @param string $pathComponents
  * @param array $componentArray
  */
 public function __construct(ContainerInterface $container, Packages $packages, $pathLib = "", $pathComponents = "", array $componentArray)
 {
     $request = $container->get('request_stack');
     $request = $request->getCurrentRequest();
     $scheme = $request->getScheme();
     $httpHost = $request->getHttpHost();
     $asset = $packages->getUrl($pathComponents);
     $this->pathLib = $packages->getUrl($pathLib);
     $this->pathComponents = $scheme . '://' . $httpHost . $asset;
     $this->componentArray = $componentArray;
 }
 /**
  * @param $filename
  *
  * @return string
  */
 public function visualizar_archivo($filename = null)
 {
     if ($filename) {
         $pathFile = $this->uploads_directory_name . '/' . $filename;
         $file = new File($pathFile);
         $img = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'pjpeg'];
         if (in_array($file->getExtension(), $img)) {
             return '<img src="' . $this->packages->getUrl($pathFile) . '" height="60">';
         }
         return '<a href="' . $this->packages->getUrl($pathFile) . '" download>Descargar archivo</a>';
     }
 }
Esempio n. 6
0
 /**
  * Add a file asset to the queue.
  *
  * @param FileAssetInterface $asset
  *
  * @throws \InvalidArgumentException
  */
 public function add(FileAssetInterface $asset)
 {
     $url = $this->packages->getUrl($asset->getPath(), $asset->getPackageName());
     $asset->setUrl($url);
     if ($asset->getType() === 'javascript') {
         $this->javascript[$url] = $asset;
     } elseif ($asset->getType() === 'stylesheet') {
         $this->stylesheet[$url] = $asset;
     } else {
         throw new \InvalidArgumentException(sprintf('Requested asset type %s is not valid.', $asset->getType()));
     }
 }
Esempio n. 7
0
 /**
  * Add base snippets to the response.
  */
 protected function addSnippets()
 {
     $generatorSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback('<meta name="generator" content="Bolt">');
     $this->queue->add($generatorSnippet);
     $canonicalUrl = $this->canonical->getUrl();
     $canonicalSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback($this->encode('<link rel="canonical" href="%s">', $canonicalUrl));
     $this->queue->add($canonicalSnippet);
     if ($favicon = $this->config->get('general/favicon')) {
         $faviconUrl = $this->packages->getUrl($favicon, 'theme');
         $faviconSnippet = (new Snippet())->setLocation(Target::END_OF_HEAD)->setCallback($this->encode('<link rel="shortcut icon" href="%s">', $faviconUrl));
         $this->queue->add($faviconSnippet);
     }
 }
Esempio n. 8
0
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $definitions = $this->widgetDefinitionsRegistry->getWidgetDefinitions();
     if ($definitions->isEmpty()) {
         return;
     }
     $definitions = $definitions->toArray();
     foreach ($definitions as &$definition) {
         if (!empty($definition['icon'])) {
             $definition['icon'] = $this->assetHelper->getUrl($definition['icon']);
         }
     }
     $this->widgetDefinitionsRegistry->setWidgetDefinitions($definitions);
 }
Esempio n. 9
0
 /**
  * Get files from a specified source data
  *
  * @param array $source
  * @return array
  */
 public function getFiles($source)
 {
     $resources = [];
     if (isset($source['path'], $source['url'])) {
         $finder = new Finder();
         $pathParts = explode('/', $source['path']);
         $fileNamePattern = array_pop($pathParts);
         $files = $finder->name($fileNamePattern)->in(implode(DIRECTORY_SEPARATOR, $pathParts));
         /** @var \SplFileInfo[] $files */
         foreach ($files as $file) {
             $resources[$file->getFilename()] = $this->assetHelper->getUrl(rtrim($source['url'], '/') . '/' . $file->getFilename());
         }
     }
     return $resources;
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $defaultWysiwygOptions = ['plugins' => ['textcolor', 'code', 'link', 'image', 'table', 'hr', 'preview', 'media'], 'toolbar_type' => self::TOOLBAR_FULL, 'skin_url' => 'bundles/oroform/css/tinymce', 'valid_elements' => implode(',', $this->htmlTagProvider->getAllowedElements()), 'menubar' => false, 'statusbar' => false, 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => true, 'width' => 950, 'height' => 550];
     $defaults = ['random_id' => true, 'wysiwyg_enabled' => (bool) $this->configManager->get('oro_form.wysiwyg_enabled'), 'wysiwyg_options' => $defaultWysiwygOptions, 'page-component' => ['module' => 'oroui/js/app/components/view-component', 'options' => ['view' => 'oroform/js/app/views/wysiwig-editor/wysiwyg-editor-view', 'content_css' => 'bundles/oroform/css/wysiwyg-editor.css']]];
     $resolver->setDefaults($defaults);
     $resolver->setNormalizers(['wysiwyg_options' => function (Options $options, $wysiwygOptions) use($defaultWysiwygOptions) {
         if (empty($wysiwygOptions['toolbar_type']) || !array_key_exists($wysiwygOptions['toolbar_type'], $this->toolbars)) {
             $toolbarType = self::TOOLBAR_DEFAULT;
         } else {
             $toolbarType = $wysiwygOptions['toolbar_type'];
         }
         $wysiwygOptions['toolbar'] = $this->toolbars[$toolbarType];
         $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions);
         unset($wysiwygOptions['toolbar_type']);
         return $wysiwygOptions;
     }, 'attr' => function (Options $options, $attr) {
         $pageComponent = $options->get('page-component');
         $wysiwygOptions = (array) $options->get('wysiwyg_options');
         if ($this->assetHelper) {
             if (!empty($pageComponent['options']['content_css'])) {
                 $pageComponent['options']['content_css'] = $this->assetHelper->getUrl($pageComponent['options']['content_css']);
             }
             if (!empty($wysiwygOptions['skin_url'])) {
                 $wysiwygOptions['skin_url'] = $this->assetHelper->getUrl($wysiwygOptions['skin_url']);
             }
         }
         $pageComponent['options'] = array_merge($pageComponent['options'], $wysiwygOptions);
         $pageComponent['options']['enabled'] = (bool) $options->get('wysiwyg_enabled');
         $attr['data-page-component-module'] = $pageComponent['module'];
         $attr['data-page-component-options'] = json_encode($pageComponent['options']);
         return $attr;
     }]);
 }
 /**
  * Returns a list of choice attributes for the given integration type
  *
  * @param string $typeName
  *
  * @return array
  */
 protected function getChoiceAttributes($typeName)
 {
     $attributes = [];
     $data = $this->itemsCache[$typeName];
     if (!empty($data['icon'])) {
         $attributes['data-icon'] = $this->assetHelper->getUrl($data['icon']);
     }
     return $attributes;
 }
 /**
  * Generate an url in both Symfony 2 and Symfony 3 compatible ways.
  *
  * @param string $url
  *
  * @return string
  */
 private function generateUrl($url)
 {
     if ($this->packages) {
         return $this->packages->getUrl($url);
     }
     if ($this->coreAssetsHelper) {
         return $this->coreAssetsHelper->getUrl($url);
     }
     return $url;
 }
Esempio n. 13
0
 /**
  * @param mixed[]        $reference
  * @param AssetInterface $asset
  *
  * @return string
  */
 public function rewrite(array $reference, AssetInterface $asset)
 {
     if (!$this->isRewritable($reference['url'], $asset->getSourcePath(), $asset->getTargetPath())) {
         return $reference[0];
     }
     $absoluteSourcePath = $this->getAssetPath(dirname($this->createAssetPath($asset->getSourceRoot(), $asset->getSourcePath())), parse_url($reference['url'])['path']);
     $webTargetPath = $this->createAssetPath($this->rewriteDirectory, $this->namer->name($absoluteSourcePath, $asset));
     $absoluteTargetPath = $this->webDirectory . $webTargetPath;
     $this->filesystem->{$this->strategy}($absoluteSourcePath, $absoluteTargetPath, true);
     return str_replace($reference['url'], $this->packages->getUrl($webTargetPath), $reference[0]);
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $assetsVersionBaseUrl = '';
     $assetsVersionFormatted = '';
     if ($this->assetHelper) {
         /**
          * As we can't get "assets_version_format" parameter and method "getVersion" returns only version value
          * without any formatting - we have to calculate formatted version url's parameter to be used inside
          * WYSIWYG editor.
          */
         $assetsVersionBaseUrl = $this->assetHelper->getUrl('/');
         $assetsVersionFormatted = substr($assetsVersionBaseUrl, strrpos($assetsVersionBaseUrl, '/') + 1);
     }
     $defaultWysiwygOptions = ['plugins' => self::$defaultPlugins, 'toolbar_type' => self::TOOLBAR_DEFAULT, 'skin_url' => 'bundles/oroform/css/tinymce', 'valid_elements' => implode(',', $this->htmlTagProvider->getAllowedElements()), 'menubar' => false, 'statusbar' => false, 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => true, 'cache_suffix' => $assetsVersionFormatted, 'document_base_url' => $assetsVersionBaseUrl];
     $defaults = ['wysiwyg_enabled' => (bool) $this->configManager->get('oro_form.wysiwyg_enabled'), 'wysiwyg_options' => $defaultWysiwygOptions, 'page-component' => ['module' => 'oroui/js/app/components/view-component', 'options' => ['view' => 'oroform/js/app/views/wysiwig-editor/wysiwyg-editor-view', 'content_css' => 'bundles/oroform/css/wysiwyg-editor.css']]];
     $resolver->setDefaults($defaults);
     $resolver->setNormalizers(['wysiwyg_options' => function (Options $options, $wysiwygOptions) use($defaultWysiwygOptions) {
         if (!empty($wysiwygOptions['toolbar'])) {
             $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions);
             unset($wysiwygOptions['toolbar_type']);
             return $wysiwygOptions;
         }
         if (empty($wysiwygOptions['toolbar_type']) || !array_key_exists($wysiwygOptions['toolbar_type'], self::$toolbars)) {
             $toolbarType = self::TOOLBAR_DEFAULT;
         } else {
             $toolbarType = $wysiwygOptions['toolbar_type'];
         }
         $wysiwygOptions['toolbar'] = self::$toolbars[$toolbarType];
         $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions);
         unset($wysiwygOptions['toolbar_type']);
         return $wysiwygOptions;
     }, 'attr' => function (Options $options, $attr) {
         $pageComponent = $options->get('page-component');
         $wysiwygOptions = (array) $options->get('wysiwyg_options');
         $pageComponent['options'] = array_merge($pageComponent['options'], $wysiwygOptions);
         $pageComponent['options']['enabled'] = (bool) $options->get('wysiwyg_enabled');
         $attr['data-page-component-module'] = $pageComponent['module'];
         $attr['data-page-component-options'] = json_encode($pageComponent['options']);
         return $attr;
     }]);
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  */
 protected function doEvaluate($context)
 {
     $path = $this->resolveValue($context, $this->path);
     if ($path === null) {
         return $path;
     }
     if (!is_string($path)) {
         $this->addError($context, sprintf('Expected a string value for the path, got "%s".', is_object($path) ? get_class($path) : gettype($path)));
         return $path;
     }
     $packageName = $this->resolveValue($context, $this->packageName);
     if ($packageName !== null && !is_string($packageName)) {
         $this->addError($context, sprintf('Expected null or a string value for the package name, got "%s".', is_object($packageName) ? get_class($packageName) : gettype($packageName)));
         return $path;
     }
     return $this->packages->getUrl($this->normalizeAssetsPath($path), $packageName);
 }
 /**
  * {@inheritdoc}
  */
 public function getUrl($path, $packageName = null)
 {
     return $this->assetPackages->getUrl($path, $packageName);
 }
 public function testGetUrl()
 {
     $packages = new Packages(new Package(new StaticVersionStrategy('default')), array('a' => new Package(new StaticVersionStrategy('a'))));
     $this->assertEquals('/foo?default', $packages->getUrl('/foo'));
     $this->assertEquals('/foo?a', $packages->getUrl('/foo', 'a'));
 }
Esempio n. 18
0
 /**
  * @param $path
  *
  * @return string
  */
 public function getBasePath($path)
 {
     return $this->fixPath($this->assetsHelper->getUrl($path));
 }
Esempio n. 19
0
 /**
  * Returns the public path of an asset
  *
  * Absolute paths (i.e. http://...) are returned unmodified.
  *
  * @param string $path A public path
  *
  * @return string A public path which takes into account the base path
  * and URL path
  */
 public function getAssetUrl_modifier($path, $package = null)
 {
     return $this->packages->getUrl($path, $package);
 }
 * Created by PhpStorm.
 * User: dima
 * Date: 15.09.15
 * Time: 20:40
 */
namespace {
    require_once __DIR__ . '/vendor/autoload.php';
    use Symfony\Component\Asset\Context\RequestStackContext;
    use Symfony\Component\Asset\Packages;
    use Symfony\Component\Asset\PathPackage;
    use Symfony\Component\Asset\UrlPackage;
    use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
    use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\RequestStack;
    $requestStack = new RequestStack();
    $requestStack->push(Request::createFromGlobals());
    $requestStackContext = new RequestStackContext($requestStack);
    $jsAssetsPackage = new PathPackage('/asset/js/', new StaticVersionStrategy('v1', '%1$s?%2$s'), $requestStackContext);
    $cssAssetsPackage = new PathPackage('/asset/css/', new StaticVersionStrategy('v1', '%1$s?%2$s'), $requestStackContext);
    $imgAssetsPackage = new PathPackage('/asset/img/', new StaticVersionStrategy('v1', '%1$s?%2$s'), $requestStackContext);
    $jqueryPackage = new UrlPackage(['https://code.jquery.com/', 'http://code.jquery.com/'], new EmptyVersionStrategy(), $requestStackContext);
    $namedPackages = ['js' => $jsAssetsPackage, 'jquery-cdn' => $jqueryPackage, 'css' => $cssAssetsPackage, 'img' => $imgAssetsPackage];
    $packages = new Packages(null, $namedPackages);
    echo '<pre>';
    echo $packages->getUrl('react.js', 'js'), "\n";
    echo $packages->getUrl('jquery-2.1.4.min.js', 'jquery-cdn'), "\n";
    echo $packages->getUrl('style.css', 'css'), "\n";
    echo $packages->getUrl('image.png', 'img'), "\n\n\n";
    require_once __DIR__ . '/loadersTest.php';
}
 /**
  * Render the locale path.
  *
  * @param $basePath
  * @param $locale
  *
  * @return string
  */
 public function renderLocalePath($basePath, $locale)
 {
     $localePath = sprintf('%s/js/locales/bootstrap-datetimepicker.%s.js', $basePath, $locale);
     return $this->packages->getUrl($localePath);
 }