コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('embed.settings');
     $scheme_options = $this->streamWrapperManager->getNames(StreamWrapperInterface::WRITE_VISIBLE);
     $form['file_scheme'] = ['#type' => 'radios', '#title' => $this->t('Upload destination'), '#options' => $scheme_options, '#default_value' => $config->get('file_scheme'), '#description' => $this->t('Select where the uploaded button icon files should be stored.')];
     $form['upload_directory'] = ['#type' => 'textfield', '#title' => $this->t('File directory'), '#default_value' => $config->get('upload_directory'), '#description' => $this->t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), '#element_validate' => [[get_class($this), 'validateDirectory']]];
     return parent::buildForm($form, $form_state);
 }
コード例 #2
0
ファイル: ImageStyleRoutes.php プロジェクト: aWEBoLabs/taxi
 /**
  * Returns an array of route objects.
  *
  * @return \Symfony\Component\Routing\Route[]
  *   An array of route objects.
  */
 public function routes()
 {
     $routes = array();
     // Generate image derivatives of publicly available files. If clean URLs are
     // disabled image derivatives will always be served through the menu system.
     // If clean URLs are enabled and the image derivative already exists, PHP
     // will be bypassed.
     $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath();
     $routes['image.style_public'] = new Route('/' . $directory_path . '/styles/{image_style}/{scheme}', array('_controller' => 'Drupal\\image\\Controller\\ImageStyleDownloadController::deliver'), array('_access' => 'TRUE'));
     return $routes;
 }
コード例 #3
0
ファイル: StreamLocator.php プロジェクト: hugronaphor/cornel
 /**
  * Locates a library.
  *
  * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
  *   The library to locate.
  *
  * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
  */
 public function locate(LocalLibraryInterface $library)
 {
     /** @var \Drupal\Core\StreamWrapper\LocalStream $stream_wrapper */
     $stream_wrapper = $this->streamWrapperManager->getViaScheme($this->scheme);
     assert('$stream_wrapper instanceof \\Drupal\\Core\\StreamWrapper\\LocalStream');
     // Calling LocalStream::getDirectoryPath() explicitly avoids the realpath()
     // usage in LocalStream::getLocalPath(), which breaks if Libraries API is
     // symbolically linked into the Drupal installation.
     $path = $stream_wrapper->getDirectoryPath() . '/' . $library->getId();
     if (is_dir($path) && is_readable($path)) {
         $library->setLocalPath($path);
     } else {
         $library->setUninstalled();
     }
 }
コード例 #4
0
ファイル: GDToolkit.php プロジェクト: eigentor/tommiblog
 /**
  * {@inheritdoc}
  */
 public function save($destination)
 {
     $scheme = file_uri_scheme($destination);
     // Work around lack of stream wrapper support in imagejpeg() and imagepng().
     if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
         // If destination is not local, save image to temporary local file.
         $local_wrappers = $this->streamWrapperManager->getWrappers(StreamWrapperInterface::LOCAL);
         if (!isset($local_wrappers[$scheme])) {
             $permanent_destination = $destination;
             $destination = drupal_tempnam('temporary://', 'gd_');
         }
         // Convert stream wrapper URI to normal path.
         $destination = drupal_realpath($destination);
     }
     $function = 'image' . image_type_to_extension($this->getType(), FALSE);
     if (!function_exists($function)) {
         return FALSE;
     }
     if ($this->getType() == IMAGETYPE_JPEG) {
         $success = $function($this->getResource(), $destination, $this->configFactory->get('system.image.gd')->get('jpeg_quality'));
     } else {
         // Always save PNG images with full transparency.
         if ($this->getType() == IMAGETYPE_PNG) {
             imagealphablending($this->getResource(), FALSE);
             imagesavealpha($this->getResource(), TRUE);
         }
         $success = $function($this->getResource(), $destination);
     }
     // Move temporary local file to remote destination.
     if (isset($permanent_destination) && $success) {
         return (bool) file_unmanaged_move($destination, $permanent_destination, FILE_EXISTS_REPLACE);
     }
     return $success;
 }
コード例 #5
0
ファイル: FileSystem.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function validScheme($scheme)
 {
     if (!$scheme) {
         return FALSE;
     }
     return class_exists($this->streamWrapperManager->getClass($scheme));
 }
コード例 #6
0
 /**
  * Prepare Url objects to prevent exceptions by the URL generator.
  *
  * Helper function to get us an external URL if this is legal, and to catch
  * the exception Drupal throws if this is not possible.
  *
  * In Drupal 8, the URL generator is very sensitive to how you set things
  * up, and some functions, in particular LinkGeneratorTrait::l(), will throw
  * exceptions if you deviate from what's expected. This function will raise
  * the chances your URL will be valid, and not do this.
  *
  * @param \Drupal\file\Entity\File|string $file_object
  *   A file entity object.
  *
  * @return \Drupal\Core\Url
  *   A Url object that can be displayed as an internal URL.
  */
 protected function getExternalUrl($file_object)
 {
     if ($file_object instanceof FileInterface) {
         $uri = $file_object->getFileUri();
     } else {
         // A little tricky, since file.inc is a little inconsistent, but often
         // this is a Uri.
         $uri = file_create_url($file_object);
     }
     try {
         // If we have been given a PHP stream URI, ask the stream itself if it
         // knows how to create an external URL.
         $wrapper = $this->streamWrapperManager->getViaUri($uri);
         if ($wrapper) {
             $external_url = $wrapper->getExternalUrl();
             // Some streams may not have the concept of an external URL, so we
             // check here to make sure, since the example assumes this.
             if ($external_url) {
                 $url = Url::fromUri($external_url);
                 return $url;
             }
         } else {
             $url = Url::fromUri($uri);
             // If we did not throw on ::fromUri (you can), we return the URL.
             return $url;
         }
     } catch (\Exception $e) {
         return FALSE;
     }
     return FALSE;
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     if ($wrapper = $this->streamWrapperManager->getViaUri($path)) {
         // Get the real path from the stream wrapper.
         $path = $wrapper->realpath();
     }
     if ($this->sortedGuessers === NULL) {
         // Sort is not triggered yet.
         $this->sortedGuessers = $this->sortGuessers();
     }
     foreach ($this->sortedGuessers as $guesser) {
         $mime_type = $guesser->guess($path);
         if ($mime_type !== NULL) {
             return $mime_type;
         }
     }
 }
コード例 #8
0
ファイル: FileSystemForm.php プロジェクト: nstielau/drops-8
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('system.file');
     $form['file_public_path'] = array('#type' => 'item', '#title' => t('Public file system path'), '#markup' => PublicStream::basePath(), '#description' => t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web. This must be changed in settings.php'));
     $form['file_private_path'] = array('#type' => 'item', '#title' => t('Private file system path'), '#markup' => PrivateStream::basePath() ? PrivateStream::basePath() : t('Not set'), '#description' => t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. This must be changed in settings.php'));
     $form['file_temporary_path'] = array('#type' => 'textfield', '#title' => t('Temporary directory'), '#default_value' => $config->get('path.temporary'), '#maxlength' => 255, '#description' => t('A local file system path where temporary files will be stored. This directory should not be accessible over the web.'), '#after_build' => array('system_check_directory'));
     // Any visible, writeable wrapper can potentially be used for the files
     // directory, including a remote file system that integrates with a CDN.
     $options = $this->streamWrapperManager->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE);
     if (!empty($options)) {
         $form['file_default_scheme'] = array('#type' => 'radios', '#title' => t('Default download method'), '#default_value' => $config->get('default_scheme'), '#options' => $options, '#description' => t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'));
     }
     $intervals = array(0, 21600, 43200, 86400, 604800, 2419200, 7776000);
     $period = array_combine($intervals, array_map(array($this->dateFormatter, 'formatInterval'), $intervals));
     $period[0] = t('Never');
     $form['temporary_maximum_age'] = array('#type' => 'select', '#title' => t('Delete orphaned files after'), '#default_value' => $config->get('temporary_maximum_age'), '#options' => $period, '#description' => t('Orphaned files are not referenced from any content but remain in the file system and may appear in administrative listings. <strong>Warning:</strong> If enabled, orphaned files will be permanently deleted and may not be recoverable.'));
     return parent::buildForm($form, $form_state);
 }
コード例 #9
0
ファイル: FileCopy.php プロジェクト: Greg-Boggs/electric-dev
 /**
  * Determines if the given URI or path is considered local.
  *
  * A URI or path is considered local if it either has no scheme component,
  * or the scheme is implemented by a stream wrapper which extends
  * \Drupal\Core\StreamWrapper\LocalStream.
  *
  * @param string $uri
  *   The URI or path to test.
  *
  * @return bool
  */
 protected function isLocalUri($uri)
 {
     $scheme = $this->fileSystem->uriScheme($uri);
     // The vfs scheme is vfsStream, which is used in testing. vfsStream is a
     // simulated file system that exists only in memory, but should be treated
     // as a local resource.
     if ($scheme == 'vfs') {
         $scheme = FALSE;
     }
     return $scheme === FALSE || $this->streamWrapperManager->getViaScheme($scheme) instanceof LocalStream;
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function guess($path)
 {
     if ($wrapper = $this->streamWrapperManager->getViaUri($path)) {
         // Get the real path from the stream wrapper, if available. Files stored
         // in remote file systems will not have one.
         $real_path = $wrapper->realpath();
         if ($real_path !== FALSE) {
             $path = $real_path;
         }
     }
     if ($this->sortedGuessers === NULL) {
         // Sort is not triggered yet.
         $this->sortedGuessers = $this->sortGuessers();
     }
     foreach ($this->sortedGuessers as $guesser) {
         $mime_type = $guesser->guess($path);
         if ($mime_type !== NULL) {
             return $mime_type;
         }
     }
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function processInbound($path, Request $request)
 {
     $directory_path = $this->streamWrapperManager->getViaScheme('public')->getDirectoryPath();
     if (strpos($path, '/' . $directory_path . '/styles/') === 0) {
         $path_prefix = '/' . $directory_path . '/styles/';
     } elseif (strpos($path, '/system/files/styles/') === 0) {
         $path_prefix = '/system/files/styles/';
     } else {
         return $path;
     }
     // Strip out path prefix.
     $rest = preg_replace('|^' . preg_quote($path_prefix, '|') . '|', '', $path);
     // Get the image style, scheme and path.
     if (substr_count($rest, '/') >= 2) {
         list($image_style, $scheme, $file) = explode('/', $rest, 3);
         // Set the file as query parameter.
         $request->query->set('file', $file);
         return $path_prefix . $image_style . '/' . $scheme;
     } else {
         return $path;
     }
 }
コード例 #12
0
ファイル: FileCopy.php プロジェクト: eigentor/tommiblog
 /**
  * Determines if the given URI or path is considered local.
  *
  * A URI or path is considered local if it either has no scheme component,
  * or the scheme is implemented by a stream wrapper which extends
  * \Drupal\Core\StreamWrapper\LocalStream.
  *
  * @param string $uri
  *   The URI or path to test.
  *
  * @return bool
  */
 protected function isLocalUri($uri)
 {
     $scheme = $this->fileSystem->uriScheme($uri);
     return $scheme === FALSE || $this->streamWrapperManager->getViaScheme($scheme) instanceof LocalStream;
 }