当前位置: 首页>>代码示例>>PHP>>正文


PHP UrlHelper::isExternal方法代码示例

本文整理汇总了PHP中Drupal\Component\Utility\UrlHelper::isExternal方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper::isExternal方法的具体用法?PHP UrlHelper::isExternal怎么用?PHP UrlHelper::isExternal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Component\Utility\UrlHelper的用法示例。


在下文中一共展示了UrlHelper::isExternal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * {@inheritdoc}
  */
 public function execute($object = NULL)
 {
     $url = $this->configuration['url'];
     // Leave external URLs unchanged, and assemble others as absolute URLs
     // relative to the site's base URL.
     if (!UrlHelper::isExternal($url)) {
         $parts = UrlHelper::parse($url);
         // @todo '<front>' is valid input for BC reasons, may be removed by
         //   https://www.drupal.org/node/2421941
         if ($parts['path'] === '<front>') {
             $parts['path'] = '';
         }
         $uri = 'base:' . $parts['path'];
         $options = ['query' => $parts['query'], 'fragment' => $parts['fragment'], 'absolute' => TRUE];
         // Treat this as if it's user input of a path relative to the site's
         // base URL.
         $url = $this->unroutedUrlAssembler->assemble($uri, $options);
     }
     $response = new RedirectResponse($url);
     $listener = function ($event) use($response) {
         $event->setResponse($response);
     };
     // Add the listener to the event dispatcher.
     $this->dispatcher->addListener(KernelEvents::RESPONSE, $listener);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:GotoAction.php

示例2: isValid

 /**
  * {@inheritdoc}
  */
 public function isValid($path)
 {
     // External URLs and the front page are always valid.
     if ($path == '<front>' || UrlHelper::isExternal($path)) {
         return TRUE;
     }
     // Check the routing system.
     $collection = $this->routeProvider->getRoutesByPattern('/' . $path);
     if ($collection->count() == 0) {
         return FALSE;
     }
     $request = RequestHelper::duplicate($this->requestStack->getCurrentRequest(), '/' . $path);
     $request->attributes->set('_system_path', $path);
     // We indicate that a menu administrator is running the menu access check.
     $request->attributes->set('_menu_admin', TRUE);
     // Attempt to match this path to provide a fully built request to the
     // access checker.
     try {
         $request->attributes->add($this->requestMatcher->matchRequest($request));
     } catch (ParamNotConvertedException $e) {
         return FALSE;
     }
     // Consult the access manager.
     $routes = $collection->all();
     $route = reset($routes);
     return $this->accessManager->check($route, $request, $this->account);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:PathValidator.php

示例3: assemble

 /**
  * {@inheritdoc}
  *
  * This is a helper function that calls buildExternalUrl() or buildLocalUrl()
  * based on a check of whether the path is a valid external URL.
  */
 public function assemble($uri, array $options = [])
 {
     // Note that UrlHelper::isExternal will return FALSE if the $uri has a
     // disallowed protocol.  This is later made safe since we always add at
     // least a leading slash.
     if (strpos($uri, 'base://') === 0) {
         return $this->buildLocalUrl($uri, $options);
     } elseif (UrlHelper::isExternal($uri)) {
         // UrlHelper::isExternal() only returns true for safe protocols.
         return $this->buildExternalUrl($uri, $options);
     }
     throw new \InvalidArgumentException(String::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base:// for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri]));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:19,代码来源:UnroutedUrlAssembler.php

示例4: assemble

 /**
  * {@inheritdoc}
  *
  * This is a helper function that calls buildExternalUrl() or buildLocalUrl()
  * based on a check of whether the path is a valid external URL.
  */
 public function assemble($uri, array $options = [], $collect_bubbleable_metadata = FALSE)
 {
     // Note that UrlHelper::isExternal will return FALSE if the $uri has a
     // disallowed protocol.  This is later made safe since we always add at
     // least a leading slash.
     if (parse_url($uri, PHP_URL_SCHEME) === 'base') {
         return $this->buildLocalUrl($uri, $options, $collect_bubbleable_metadata);
     } elseif (UrlHelper::isExternal($uri)) {
         // UrlHelper::isExternal() only returns true for safe protocols.
         return $this->buildExternalUrl($uri, $options, $collect_bubbleable_metadata);
     }
     throw new \InvalidArgumentException("The URI '{$uri}' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.");
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:19,代码来源:UnroutedUrlAssembler.php

示例5: get

 /**
  * {@inheritdoc}
  */
 public function get()
 {
     if (!isset($this->destination)) {
         $query = $this->requestStack->getCurrentRequest()->query;
         if (UrlHelper::isExternal($query->get('destination'))) {
             $this->destination = '/';
         } elseif ($query->has('destination')) {
             $this->destination = $query->get('destination');
         } else {
             $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::buildQuery(UrlHelper::filterQueryParameters($query->all()))]);
         }
     }
     return $this->destination;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:RedirectDestination.php

示例6: checkRedirectUrl

 /**
  * Allows manipulation of the response object when performing a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The Event to process.
  */
 public function checkRedirectUrl(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof RedirectResponse) {
         $options = array();
         $destination = $event->getRequest()->query->get('destination');
         // A destination from \Drupal::request()->query always overrides the
         // current RedirectResponse. We do not allow absolute URLs to be passed
         // via \Drupal::request()->query, as this can be an attack vector, with
         // the following exception:
         // - Absolute URLs that point to this site (i.e. same base URL and
         //   base path) are allowed.
         if ($destination && (!UrlHelper::isExternal($destination) || UrlHelper::externalIsLocal($destination, $GLOBALS['base_url']))) {
             $destination = UrlHelper::parse($destination);
             $path = $destination['path'];
             $options['query'] = $destination['query'];
             $options['fragment'] = $destination['fragment'];
             // The 'Location' HTTP header must always be absolute.
             $options['absolute'] = TRUE;
             $response->setTargetUrl($this->urlGenerator->generateFromPath($path, $options));
         }
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:RedirectResponseSubscriber.php

示例7: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $result = new FilterProcessResult($text);
     $dom = Html::load($text);
     $xpath = new \DOMXPath($dom);
     /** @var \DOMNode $node */
     foreach ($xpath->query('//img') as $node) {
         // Read the data-align attribute's value, then delete it.
         $width = $node->getAttribute('width');
         $height = $node->getAttribute('height');
         $src = $node->getAttribute('src');
         if (!UrlHelper::isExternal($src)) {
             if ($width || $height) {
                 /** @var \DOMNode $element */
                 $element = $dom->createElement('a');
                 $element->setAttribute('href', $src);
                 $node->parentNode->replaceChild($element, $node);
                 $element->appendChild($node);
             }
         }
     }
     $result->setProcessedText(Html::serialize($dom));
     return $result;
 }
开发者ID:agaric,项目名称:image_resize_filter,代码行数:27,代码来源:FilterImageLinkToSource.php

示例8: massageFormValues

 /**
  * {@inheritdoc}
  */
 public function massageFormValues(array $values, array $form, array &$form_state)
 {
     foreach ($values as &$value) {
         if (!empty($value['url'])) {
             try {
                 $parsed_url = UrlHelper::parse($value['url']);
                 // If internal links are supported, look up whether the given value is
                 // a path alias and store the system path instead.
                 if ($this->supportsInternalLinks() && !UrlHelper::isExternal($value['url'])) {
                     $parsed_url['path'] = \Drupal::service('path.alias_manager')->getPathByAlias($parsed_url['path']);
                 }
                 $url = Url::createFromPath($parsed_url['path']);
                 $url->setOption('query', $parsed_url['query']);
                 $url->setOption('fragment', $parsed_url['fragment']);
                 $url->setOption('attributes', $value['attributes']);
                 $value += $url->toArray();
                 // Reset the URL value to contain only the path.
                 $value['url'] = $parsed_url['path'];
             } catch (NotFoundHttpException $e) {
                 // Nothing to do here, LinkTypeConstraintValidator emits errors.
             } catch (MatchingRouteNotFoundException $e) {
                 // Nothing to do here, LinkTypeConstraintValidator emits errors.
             } catch (ParamNotConvertedException $e) {
                 // Nothing to do here, LinkTypeConstraintValidator emits errors.
             }
         }
     }
     return $values;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:32,代码来源:LinkWidget.php

示例9: getUrl

 /**
  * Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().
  */
 protected function getUrl($path, $access_check)
 {
     $path = ltrim($path, '/');
     $parsed_url = UrlHelper::parse($path);
     $options = [];
     if (!empty($parsed_url['query'])) {
         $options['query'] = $parsed_url['query'];
     }
     if (!empty($parsed_url['fragment'])) {
         $options['fragment'] = $parsed_url['fragment'];
     }
     if ($parsed_url['path'] == '<front>') {
         return new Url('<front>', [], $options);
     } elseif ($parsed_url['path'] == '<none>') {
         return new Url('<none>', [], $options);
     } elseif (UrlHelper::isExternal($path) && UrlHelper::isValid($path)) {
         if (empty($parsed_url['path'])) {
             return FALSE;
         }
         return Url::fromUri($path);
     }
     $request = Request::create('/' . $path);
     $attributes = $this->getPathAttributes($path, $request, $access_check);
     if (!$attributes) {
         return FALSE;
     }
     $route_name = $attributes[RouteObjectInterface::ROUTE_NAME];
     $route_parameters = $attributes['_raw_variables']->all();
     return new Url($route_name, $route_parameters, $options + ['query' => $request->query->all()]);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:PathValidator.php

示例10: massageFormValues

 /**
  * {@inheritdoc}
  */
 public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
 {
     global $base_url;
     $values = parent::massageFormValues($values, $form, $form_state);
     $file_urls = [];
     $countable_fields = $this->getSetting('file_fields');
     foreach ($countable_fields as $field) {
         $files_values = array_filter(array_column($form_state->getValue($field), 'fids'));
         foreach ($files_values as $file_value) {
             /** @var FileInterface $file */
             $file = File::load(reset($file_value));
             if ($file) {
                 $file_urls[] = $file->url();
             }
         }
     }
     // Remove removed files from access urls.
     foreach ($values as $delta => $value) {
         if (UrlHelper::isExternal($value['uri']) && UrlHelper::externalIsLocal($value['uri'], $base_url) && !in_array($value['uri'], $file_urls)) {
             unset($values[$delta]);
         }
     }
     // Add new or updated files to the access urls.
     foreach ($file_urls as $file_url) {
         if (!array_search($file_url, array_column($values, 'uri'))) {
             $values[]['uri'] = $file_url;
         }
     }
     return $values;
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:33,代码来源:UrlFileSynchronizerWidget.php

示例11: validate

 /**
  * Overrides EntityForm::validate().
  */
 public function validate(array $form, array &$form_state)
 {
     $menu_link = $this->buildEntity($form, $form_state);
     $normal_path = $this->pathAliasManager->getPathByAlias($menu_link->link_path);
     if ($menu_link->link_path != $normal_path) {
         drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path)));
         $menu_link->link_path = $normal_path;
         $form_state['values']['link_path'] = $normal_path;
     }
     if (!UrlHelper::isExternal($menu_link->link_path)) {
         $parsed_link = parse_url($menu_link->link_path);
         if (isset($parsed_link['query'])) {
             $menu_link->options['query'] = array();
             parse_str($parsed_link['query'], $menu_link->options['query']);
         } else {
             // Use unset() rather than setting to empty string
             // to avoid redundant serialized data being stored.
             unset($menu_link->options['query']);
         }
         if (isset($parsed_link['fragment'])) {
             $menu_link->options['fragment'] = $parsed_link['fragment'];
         } else {
             unset($menu_link->options['fragment']);
         }
         if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) {
             $menu_link->link_path = $parsed_link['path'];
         }
     }
     if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) {
         $this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path)));
     }
     parent::validate($form, $form_state);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:36,代码来源:MenuLinkForm.php

示例12: extractUrl

 /**
  * Breaks up a user-entered URL or path into all the relevant parts.
  *
  * @param string $url
  *   The user-entered URL or path.
  *
  * @return array
  *   The extracted parts.
  */
 protected function extractUrl($url)
 {
     $extracted = UrlHelper::parse($url);
     $external = UrlHelper::isExternal($url);
     if ($external) {
         $extracted['url'] = $extracted['path'];
         $extracted['route_name'] = NULL;
         $extracted['route_parameters'] = [];
     } else {
         $extracted['url'] = '';
         // If the path doesn't match a Drupal path, the route should end up empty.
         $extracted['route_name'] = NULL;
         $extracted['route_parameters'] = [];
         try {
             // Find the route_name.
             $url_obj = \Drupal::pathValidator()->getUrlIfValid($extracted['path']);
             if ($url_obj) {
                 $extracted['route_name'] = $url_obj->getRouteName();
                 $extracted['route_parameters'] = $url_obj->getRouteParameters();
             }
         } catch (MatchingRouteNotFoundException $e) {
             // The path doesn't match a Drupal path.
         } catch (ParamNotConvertedException $e) {
             // A path like node/99 matched a route, but the route parameter was
             // invalid (e.g. node with ID 99 does not exist).
         }
     }
     return $extracted;
 }
开发者ID:robertfoleyjr,项目名称:robertfoleyjr-d8,代码行数:38,代码来源:MenuLinkConfigForm.php

示例13: testDrupalParseUrl

 /**
  * Tests UrlHelper::parse().
  */
 function testDrupalParseUrl()
 {
     // Relative, absolute, and external URLs, without/with explicit script path,
     // without/with Drupal path.
     foreach (array('', '/', 'http://drupal.org/') as $absolute) {
         foreach (array('', 'index.php/') as $script) {
             foreach (array('', 'foo/bar') as $path) {
                 $url = $absolute . $script . $path . '?foo=bar&bar=baz&baz#foo';
                 $expected = array('path' => $absolute . $script . $path, 'query' => array('foo' => 'bar', 'bar' => 'baz', 'baz' => ''), 'fragment' => 'foo');
                 $this->assertEqual(UrlHelper::parse($url), $expected, 'URL parsed correctly.');
             }
         }
     }
     // Relative URL that is known to confuse parse_url().
     $url = 'foo/bar:1';
     $result = array('path' => 'foo/bar:1', 'query' => array(), 'fragment' => '');
     $this->assertEqual(UrlHelper::parse($url), $result, 'Relative URL parsed correctly.');
     // Test that drupal can recognize an absolute URL. Used to prevent attack vectors.
     $url = 'http://drupal.org/foo/bar?foo=bar&bar=baz&baz#foo';
     $this->assertTrue(UrlHelper::isExternal($url), 'Correctly identified an external URL.');
     // Test that UrlHelper::parse() does not allow spoofing a URL to force a malicious redirect.
     $parts = UrlHelper::parse('forged:http://cwe.mitre.org/data/definitions/601.html');
     $this->assertFalse(UrlHelper::isValid($parts['path'], TRUE), '\\Drupal\\Component\\Utility\\UrlHelper::isValid() correctly parsed a forged URL.');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:27,代码来源:UrlTest.php

示例14: extractUrl

 /**
  * Breaks up a user-entered URL or path into all the relevant parts.
  *
  * @param string $url
  *   The user-entered URL or path.
  *
  * @return array
  *   The extracted parts.
  */
 protected function extractUrl($url)
 {
     $extracted = UrlHelper::parse($url);
     $external = UrlHelper::isExternal($url);
     if ($external) {
         $extracted['url'] = $extracted['path'];
         $extracted['route_name'] = NULL;
         $extracted['route_parameters'] = array();
     } else {
         $extracted['url'] = '';
         // If the path doesn't match a Drupal path, the route should end up empty.
         $extracted['route_name'] = NULL;
         $extracted['route_parameters'] = array();
         try {
             // Find the route_name.
             $normal_path = $this->pathAliasManager->getPathByAlias($extracted['path']);
             $url_obj = Url::createFromPath($normal_path);
             $extracted['route_name'] = $url_obj->getRouteName();
             $extracted['route_parameters'] = $url_obj->getRouteParameters();
         } catch (MatchingRouteNotFoundException $e) {
             // The path doesn't match a Drupal path.
         } catch (ParamNotConvertedException $e) {
             // A path like node/99 matched a route, but the route parameter was
             // invalid (e.g. node with ID 99 does not exist).
         }
     }
     return $extracted;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:37,代码来源:MenuLinkContentForm.php

示例15: renderText

  /**
   * {@inheritdoc}
   */
  public function renderText($alter) {
    // We need to preserve the safeness of the value regardless of the
    // alterations made by this method. Any alterations or replacements made
    // within this method need to ensure that at the minimum the result is
    // XSS admin filtered. See self::renderAltered() as an example that does.
    $value_is_safe = $this->last_render instanceof MarkupInterface;
    // Cast to a string so that empty checks and string functions work as
    // expected.
    $value = (string) $this->last_render;

    if (!empty($alter['alter_text']) && $alter['text'] !== '') {
      $tokens = $this->getRenderTokens($alter);
      $value = $this->renderAltered($alter, $tokens);
    }

    if (!empty($this->options['alter']['trim_whitespace'])) {
      $value = trim($value);
    }

    // Check if there should be no further rewrite for empty values.
    $no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->isValueEmpty($this->original_value, $this->options['empty_zero']);

    // Check whether the value is empty and return nothing, so the field isn't rendered.
    // First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE).
    // For numeric values you can specify whether "0"/0 should be empty.
    if ((($this->options['hide_empty'] && empty($value))
        || ($alter['phase'] != static::RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty))
      && $this->isValueEmpty($value, $this->options['empty_zero'], FALSE)) {
      return '';
    }
    // Only in empty phase.
    if ($alter['phase'] == static::RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty) {
      // If we got here then $alter contains the value of "No results text"
      // and so there is nothing left to do.
      return ViewsRenderPipelineMarkup::create($value);
    }

    if (!empty($alter['strip_tags'])) {
      $value = strip_tags($value, $alter['preserve_tags']);
    }

    $more_link = '';
    if (!empty($alter['trim']) && !empty($alter['max_length'])) {
      $length = strlen($value);
      $value = $this->renderTrimText($alter, $value);
      if ($this->options['alter']['more_link'] && strlen($value) < $length) {
        $tokens = $this->getRenderTokens($alter);
        $more_link_text = $this->options['alter']['more_link_text'] ? $this->options['alter']['more_link_text'] : $this->t('more');
        $more_link_text = strtr(Xss::filterAdmin($more_link_text), $tokens);
        $more_link_path = $this->options['alter']['more_link_path'];
        $more_link_path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($more_link_path, $tokens)));

        // Make sure that paths which were run through URL generation work as
        // well.
        $base_path = base_path();
        // Checks whether the path starts with the base_path.
        if (strpos($more_link_path, $base_path) === 0) {
          $more_link_path = Unicode::substr($more_link_path, Unicode::strlen($base_path));
        }

        // @todo Views should expect and store a leading /. See
        //   https://www.drupal.org/node/2423913.
        $options = array(
          'attributes' => array(
            'class' => array(
              'views-more-link',
            ),
          ),
        );
        if (UrlHelper::isExternal($more_link_path)) {
          $more_link_url = CoreUrl::fromUri($more_link_path, $options);
        }
        else {
          $more_link_url = CoreUrl::fromUserInput('/' . $more_link_path, $options);
        }
        $more_link = ' ' . $this->linkGenerator()->generate($more_link_text, $more_link_url);
      }
    }

    if (!empty($alter['nl2br'])) {
      $value = nl2br($value);
    }

    if ($value_is_safe) {
      $value = ViewsRenderPipelineMarkup::create($value);
    }
    $this->last_render_text = $value;

    if (!empty($alter['make_link']) && (!empty($alter['path']) || !empty($alter['url']))) {
      if (!isset($tokens)) {
        $tokens = $this->getRenderTokens($alter);
      }
      $value = $this->renderAsLink($alter, $value, $tokens);
    }

    // Preserve whether or not the string is safe. Since $more_link comes from
    // \Drupal::l(), it is safe to append. Check if the value is an instance of
//.........这里部分代码省略.........
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:101,代码来源:FieldPluginBase.php


注:本文中的Drupal\Component\Utility\UrlHelper::isExternal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。