url

Versions
mediamosa-21
url($path = NULL, array $options = array())

Generate a URL.

When creating links in modules, consider whether l() could be a better alternative than url().

Parameters

$path The Drupal path being linked to, such as "admin/content", or an existing URL like "http://drupal.org/". The special path '<front>' may also be given and will generate the site's base URL.

$options An associative array of additional options, with the following keys:

  • 'query': An array of query key/value-pairs (without any URL-encoding) to append to the link.
  • 'fragment': A fragment identifier (or named anchor) to append to the link. Do not include the leading '#' character.
  • 'absolute': Defaults to FALSE. Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in a RSS feed.
  • 'alias': Defaults to FALSE. Whether the given path is a URL alias already.
  • 'external': Whether the given path is an external URL.
  • 'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to look up the alias for the URL. If $options['language'] is omitted, the global $language will be used.
  • 'https': Whether this URL should point to a secure location. If not defined, the current scheme is used, so the user stays on http or https respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can only be enforced when the variable 'https' is set to TRUE.
  • 'base_url': Only used internally, to modify the base URL when a language dependent URL requires so.
  • 'prefix': Only used internally, to modify the path when a language dependent URL requires so.

Return value

A string containing a URL to the given path.

▾ 203 functions call url()

aggregator_block_view in modules/aggregator/aggregator.module
Implements hook_block_view().
aggregator_form_aggregator_admin_form_alter in modules/aggregator/aggregator.processor.inc
Implements hook_form_aggregator_admin_form_alter().
aggregator_form_feed in modules/aggregator/aggregator.admin.inc
Form builder; Generate a form to add/edit feed sources.
aggregator_form_opml in modules/aggregator/aggregator.admin.inc
Form builder; Generate a form to import feeds from OPML.
aggregator_help in modules/aggregator/aggregator.module
Implements hook_help().
aggregator_page_categories in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the categories used by the aggregator.
aggregator_page_category in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the items aggregated in a particular category.
aggregator_page_last in modules/aggregator/aggregator.pages.inc
Menu callback; displays the most recent items gathered from any feed.
aggregator_page_sources in modules/aggregator/aggregator.pages.inc
Menu callback; displays all the feeds used by the aggregator.
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
ajax_process_form in includes/ajax.inc
Add AJAX information about a form element to the page to communicate with JavaScript.
batch_process in includes/form.inc
Processes the batch.
block_admin_display_form in modules/block/block.admin.inc
Generate main blocks administration form.
block_custom_block_form in modules/block/block.module
Define the custom block form.
block_help in modules/block/block.module
Implements hook_help().
block_update_7004 in modules/block/block.install
Add new blocks to new regions, migrate custom variables to blocks.
blog_block_view in modules/blog/blog.module
Implements hook_block_view().
blog_feed_last in modules/blog/blog.pages.inc
Menu callback; displays an RSS feed containing recent blog entries of all users.
blog_feed_user in modules/blog/blog.pages.inc
Menu callback; displays an RSS feed containing recent blog entries of a given user.
blog_help in modules/blog/blog.module
Implements hook_help().
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
book_help in modules/book/book.module
Implements hook_help().
coder_review_admin_settings in sites/all/modules/coder/coder_review/coder_review.module
Implements settings page.
coder_review_page_form in sites/all/modules/coder/coder_review/coder_review.module
Implements hook_form().
color_help in modules/color/color.module
Implements hook_help().
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
comment_help in modules/comment/comment.module
Implements hook_help().
comment_node_view in modules/comment/comment.module
Implements hook_node_view().
comment_tokens in modules/comment/comment.tokens.inc
Implements hook_tokens().
contact_form_user_profile_form_alter in modules/contact/contact.module
Implements hook_form_FORM_ID_alter().
contact_help in modules/contact/contact.module
Implements hook_help().
contact_mail in modules/contact/contact.module
Implements hook_mail().
contact_site_form in modules/contact/contact.pages.inc
Form builder; the site-wide contact form.
dashboard_admin in modules/dashboard/dashboard.module
Dashboard page callback.
dashboard_help in modules/dashboard/dashboard.module
Implements hook_help().
dblog_form_system_logging_settings_alter in modules/dblog/dblog.module
Implements hook_form_FORM_ID_alter().
dblog_help in modules/dblog/dblog.module
Implements hook_help().
devel_admin_settings in sites/all/modules/devel/devel.module
devel_generate_content_form in sites/all/modules/devel/devel_generate.module
devel_init in sites/all/modules/devel/devel.module
Implements hook_init().
devel_menu in sites/all/modules/devel/devel.module
Implementationation of hook_menu().
devel_node_access_block_view in sites/all/modules/devel/devel_node_access.module
devel_node_access_help in sites/all/modules/devel/devel_node_access.module
Implements hook_help().
devel_themer_exit in sites/all/modules/devel/devel_themer.module
devel_themer_popup in sites/all/modules/devel/devel_themer.module
Return the popup template placed here for easy editing
devel_themer_requirements in sites/all/modules/devel/devel_themer.install
drupal_goto in includes/common.inc
Send the user to a different Drupal page.
field_help in modules/field/field.module
Implements hook_help().
field_sql_storage_help in modules/field/modules/field_sql_storage/field_sql_storage.module
Implements hook_help().
field_ui_display_overview_form in modules/field_ui/field_ui.admin.inc
Menu callback; presents a listing of fields display settings for a bundle.
field_ui_help in modules/field_ui/field_ui.module
Implements hook_help().
file_help in modules/file/file.module
Implements hook_help().
filter_help in modules/filter/filter.module
Implements hook_help().
filter_update_7005 in modules/filter/filter.install
Integrate text formats with the user permissions system.
forum_block_view_pre_render in modules/forum/forum.module
A #pre_render callback. Lists nodes based on the element's #query property. *
forum_confirm_delete in modules/forum/forum.admin.inc
Returns a confirmation page for deleting a forum taxonomy term.
forum_help in modules/forum/forum.module
Implements hook_help().
forum_menu_local_tasks_alter in modules/forum/forum.module
Implements hook_menu_local_tasks_alter().
forum_overview in modules/forum/forum.admin.inc
Returns an overview list of existing forums and containers
help_help in modules/help/help.module
Implements hook_help().
hook_help in modules/help/help.api.php
Provide online user help.
hook_mail in modules/system/system.api.php
Prepare a message based on parameters; called from drupal_mail().
hook_requirements in modules/system/system.api.php
Check installation requirements and do status reporting.
hook_search_execute in modules/search/search.api.php
Execute a search for a set of key words.
hook_tokens in modules/system/system.api.php
Provide replacement values for placeholder tokens.
hook_user_login in modules/user/user.api.php
The user just logged in.
image_help in modules/image/image.module
Implement of hook_help().
image_style_url in modules/image/image.module
Return the URL for an image derivative given a style and image path.
install_finished in includes/install.core.inc
Installation task; perform final steps and display a 'finished' page.
l in includes/common.inc
Format an internal Drupal link.
list_help in modules/field/modules/list/list.module
Implements hook_help().
locale_form_node_type_form_alter in modules/locale/locale.module
Implements hook_form_FORM_ID_alter().
locale_help in modules/locale/locale.module
Implements hook_help().
locale_languages_predefined_form_submit in modules/locale/locale.admin.inc
Process the language addition form submission.
mediamosa_maintenance_browse_simpletest_result_form in sites/all/modules/mediamosa/maintenance/browse/mediamosa_maintenance_browse_simpletest.inc
wrapper for displaying the results.
menu_help in modules/menu/menu.module
Implements hook_help().
menu_overview_form in modules/menu/menu.admin.inc
Form for editing an entire menu tree at once.
node_block_view in modules/node/node.module
Implements hook_block_view().
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_help in modules/node/node.module
Implements hook_help().
node_overview_types in modules/node/content_types.inc
Displays the content type admin overview page.
node_page_default in modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
node_page_view in modules/node/node.module
Menu callback; view a single node.
node_search_execute in modules/node/node.module
Implements hook_search_execute().
node_tokens in modules/node/node.tokens.inc
Implements hook_tokens().
number_help in modules/field/modules/number/number.module
Implements hook_help().
openid_authentication in modules/openid/openid.module
Authenticate a user or attempt registration.
openid_authentication_request in modules/openid/openid.module
openid_login_validate in modules/openid/openid.module
Login form _validate hook
openid_test_html_openid1 in modules/openid/tests/openid_test.module
Menu callback; regular HTML page with OpenID 1.0 <link> element.
openid_test_html_openid2 in modules/openid/tests/openid_test.module
Menu callback; regular HTML page with OpenID 2.0 <link> element.
openid_test_yadis_http_equiv in modules/openid/tests/openid_test.module
Menu callback; regular HTML page with <meta> element.
openid_test_yadis_xrds in modules/openid/tests/openid_test.module
Menu callback; XRDS document that references the OP Endpoint URL.
openid_test_yadis_x_xrds_location in modules/openid/tests/openid_test.module
Menu callback; regular HTML page with an X-XRDS-Location HTTP header.
openid_user_add_submit in modules/openid/openid.pages.inc
options_help in modules/field/modules/options/options.module
Implements hook_help().
overlay_close_dialog in modules/overlay/overlay.module
Close the overlay and redirect the parent window to a new path.
overlay_form_submit in modules/overlay/overlay.module
Generic form submit handler.
path_admin_form in modules/path/path.admin.inc
Return a form for editing or creating an individual URL alias.
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases.
path_help in modules/path/path.module
Implements hook_help().
performance_requirements in sites/all/modules/devel/performance/performance.install
performance_view_details in sites/all/modules/devel/performance/performance.module
performance_view_summary in sites/all/modules/devel/performance/performance.module
php_help in modules/php/php.module
Implements hook_help().
poll_help in modules/poll/poll.module
Implements hook_help().
profile_block_configure in modules/profile/profile.module
Implements hook_block_configure().
profile_field_delete in modules/profile/profile.admin.inc
Menu callback; deletes a field from all user profiles.
profile_help in modules/profile/profile.module
Implements hook_help().
rdf_comment_load in modules/rdf/rdf.module
Implements hook_comment_load().
rdf_preprocess_comment in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
rdf_preprocess_taxonomy_term in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
rdf_preprocess_username in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
rdf_preprocess_user_profile in modules/rdf/rdf.module
Implements MODULE_preprocess_HOOK().
search_admin_settings in modules/search/search.admin.inc
Menu callback; displays the search module settings page.
search_form in modules/search/search.module
Render a search form.
search_help in modules/search/search.module
Implements hook_help().
shortcut_help in modules/shortcut/shortcut.module
Implements hook_help().
shortcut_set_switch_submit in modules/shortcut/shortcut.admin.inc
Submit handler for shortcut_set_switch().
simpletest_help in modules/simpletest/simpletest.module
Implements hook_help().
simpletest_requirements in modules/simpletest/simpletest.install
Check that the cURL extension exists for PHP.
simpletest_result_form in modules/simpletest/simpletest.pages.inc
Test results form for $test_id.
statistics_access_log in modules/statistics/statistics.admin.inc
Menu callback; Displays recent page accesses.
statistics_help in modules/statistics/statistics.module
Implements hook_help().
statistics_settings_form in modules/statistics/statistics.admin.inc
Form builder; Configure access logging.
system_admin_config_page in modules/system/system.admin.inc
Menu callback; Provide the administration overview page.
system_authorized_get_url in modules/system/system.module
Return the URL for the authorize.php script.
system_check_http_request in modules/system/system.module
Checks whether the server is capable of issuing HTTP requests.
system_configure_date_formats_form in modules/system/system.admin.inc
Allow users to add additional date formats.
system_date_time_formats in modules/system/system.admin.inc
Displays the date format strings overview page.
system_date_time_settings in modules/system/system.admin.inc
Form builder; Configure the site date and time settings.
system_help in modules/system/system.module
Implements hook_help().
system_image_toolkit_settings in modules/system/system.admin.inc
Form builder; Configure site image toolkit usage.
system_main_admin_page in modules/system/system.admin.inc
Menu callback; Provide the administration overview page.
system_modules in modules/system/system.admin.inc
Menu callback; provides module enable/disable interface.
system_modules_uninstall in modules/system/system.admin.inc
Builds a form of currently disabled modules.
system_performance_settings in modules/system/system.admin.inc
Form builder; Configure site performance settings.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_site_information_settings in modules/system/system.admin.inc
Form builder; The general site information form.
system_site_maintenance_mode in modules/system/system.admin.inc
Form builder; Configure the site's maintenance status.
system_test_redirect in modules/simpletest/tests/system_test.module
system_tokens in modules/system/system.tokens.inc
Implements hook_tokens().
system_user_login in modules/system/system.module
Implements hook_user_login().
taxonomy_help in modules/taxonomy/taxonomy.module
Implements hook_help().
taxonomy_overview_terms in modules/taxonomy/taxonomy.admin.inc
Form builder for the taxonomy terms overview.
taxonomy_term_feed in modules/taxonomy/taxonomy.pages.inc
Generate the content feed for a taxonomy term.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
taxonomy_tokens in modules/taxonomy/taxonomy.tokens.inc
Implements hook_tokens().
template_preprocess_aggregator_feed_source in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-feed-source.tpl.php.
template_preprocess_aggregator_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-item.tpl.php.
template_preprocess_book_navigation in modules/book/book.module
Process variables for book-navigation.tpl.php.
template_preprocess_forums in modules/forum/forum.module
Process variables for forums.tpl.php
template_preprocess_forum_list in modules/forum/forum.module
Process variables to format a forum listing.
template_preprocess_forum_topic_list in modules/forum/forum.module
Preprocess variables to format the topic listing.
template_preprocess_maintenance_page in includes/theme.inc
The variables array generated here is a mirror of template_preprocess_page(). This preprocessor will run its course when theme_maintenance_page() is invoked. It is also used in theme_install_page() and theme_update_page() to keep all the variables...
template_preprocess_node in modules/node/node.module
Process variables for node.tpl.php
template_preprocess_page in includes/theme.inc
Preprocess variables for page.tpl.php
template_preprocess_taxonomy_term in modules/taxonomy/taxonomy.module
Process variables for taxonomy-term.tpl.php.
text_help in modules/field/modules/text/text.module
Implements hook_help().
theme_aggregator_page_rss in modules/aggregator/aggregator.pages.inc
Theme the RSS output.
theme_comment_post_forbidden in modules/comment/comment.module
Theme a "you can't post comments" notice.
theme_image_style_list in modules/image/image.admin.inc
Display the page containing the list of image styles.
theme_image_style_preview in modules/image/image.admin.inc
Theme callback for displaying a preview of an image style.
theme_link in includes/theme.inc
Return a themed link.
theme_node_add_list in modules/node/node.pages.inc
Display the list of available node types for node creation.
theme_node_recent_block in modules/node/node.module
Returns a formatted list of recent nodes.
theme_taxonomy_overview_vocabularies in modules/taxonomy/taxonomy.admin.inc
Theme the vocabulary overview as a sortable list of vocabularies.
theme_textfield in includes/form.inc
Theme a textfield form element.
theme_toolbar_toggle in modules/toolbar/toolbar.module
Formats an element used to toggle the toolbar drawer's visibility.
toolbar_help in modules/toolbar/toolbar.module
Implements hook_help().
tracker_help in modules/tracker/tracker.module
Implements hook_help().
tracker_page in modules/tracker/tracker.pages.inc
Menu callback; prints a listing of active nodes on the site.
translation_form_node_type_form_alter in modules/translation/translation.module
Implements hook_form_FORM_ID_alter().
translation_help in modules/translation/translation.module
Implements hook_help().
trigger_assign_form in modules/trigger/trigger.admin.inc
Returns the form for assigning an action to a trigger.
trigger_help in modules/trigger/trigger.module
Implements hook_help().
update_help in modules/update/update.module
Implements hook_help().
update_mail in modules/update/update.module
Implements hook_mail().
update_manager_update_ready_form in modules/update/update.manager.inc
Build the form when the site is ready to update (after downloading).
update_settings in modules/update/update.settings.inc
Form builder for the update settings tab.
user_account_form_validate in modules/user/user.module
Form validation handler for user_account_form().
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.
user_cancel_url in modules/user/user.module
Generate a URL to confirm an account cancellation request.
user_help in modules/user/user.module
Implement hook_help().
user_login_block in modules/user/user.module
user_login_final_validate in modules/user/user.module
The final validation handler on the login form.
user_pass_reset in modules/user/user.pages.inc
Menu callback; process one time login link and redirects to the user page on success.
user_pass_reset_url in modules/user/user.module
Generates a unique URL for a user to login and reset their password.
user_permission in modules/user/user.module
Implements hook_permission().
user_register_submit in modules/user/user.module
Submit handler for the user registration form.
user_search_execute in modules/user/user.module
Implements hook_search_execute().
user_tokens in modules/user/user.tokens.inc
Implements hook_tokens().
_batch_progress_page_js in includes/batch.inc
Output a batch processing page with JavaScript support.
_batch_progress_page_nojs in includes/batch.inc
Output a batch processing page without JavaScript support.
_coder_review_6x_menu_node_add_warning in sites/all/modules/coder/coder_review/includes/coder_review_6x.inc
_menu_site_is_offline in includes/menu.inc
Checks whether the site is in maintenance mode.
_openid_test_endpoint_authenticate in modules/openid/tests/openid_test.module
OpenID endpoint; handle "authenticate" requests.
_openid_user_login_form_alter in modules/openid/openid.module
_php_filter_tips in modules/php/php.module
Tips callback for php filter.
_shortcut_link_form_elements in modules/shortcut/shortcut.admin.inc
Helper function for building a form for adding or editing shortcut links.
_update_message_text in modules/update/update.module
Helper function to return the appropriate message text when the site is out of date or missing a security update.
_update_no_data in modules/update/update.module
Prints a warning message when there is no data about available updates.

Code

includes/common.inc, line 1942

<?php
function url($path = NULL, array $options = array()) {
  // Merge in defaults.
  $options += array(
    'fragment' => '',
    'query' => array(),
    'absolute' => FALSE,
    'alias' => FALSE,
    'prefix' => ''
  );

  if (!isset($options['external'])) {
    // Return an external link if $path contains an allowed absolute URL.
    // Only call the slow filter_xss_bad_protocol if $path contains a ':'
    // before any / ? or #.
    // Note: we could use url_is_external($path) here, but that would
    // require another function call, and performance inside url() is critical.
    $colonpos = strpos($path, ':');
    $options['external'] = ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path));
  }

  // Preserve the original path before altering or aliasing.
  $original_path = $path;

  // Allow other modules to alter the outbound URL and options.
  drupal_alter('url_outbound', $path, $options, $original_path);

  if ($options['fragment']) {
    $options['fragment'] = '#' . $options['fragment'];
  }

  if ($options['external']) {
    // Split off the fragment.
    if (strpos($path, '#') !== FALSE) {
      list($path, $old_fragment) = explode('#', $path, 2);
      // If $options contains no fragment, take it over from the path.
      if (isset($old_fragment) && !$options['fragment']) {
        $options['fragment'] = '#' . $old_fragment;
      }
    }
    // Append the query.
    if ($options['query']) {
      $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . drupal_http_build_query($options['query']);
    }
    if (isset($options['https']) && variable_get('https', FALSE)) {
      if ($options['https'] === TRUE) {
        $path = str_replace('http://', 'https://', $path);
      }
      elseif ($options['https'] === FALSE) {
        $path = str_replace('https://', 'http://', $path);
      }
    }
    // Reassemble.
    return $path . $options['fragment'];
  }

  global $base_url, $base_secure_url, $base_insecure_url;
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['script'] = &drupal_static(__FUNCTION__);
  }
  $script = &$drupal_static_fast['script'];

  if (!isset($script)) {
    // On some web servers, such as IIS, we can't omit "index.php". So, we
    // generate "index.php?q=foo" instead of "?q=foo" on anything that is not
    // Apache.
    $script = (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === FALSE) ? 'index.php' : '';
  }

  // The base_url might be rewritten from the language rewrite in domain mode.
  if (!isset($options['base_url'])) {
    if (isset($options['https']) && variable_get('https', FALSE)) {
      if ($options['https'] === TRUE) {
        $options['base_url'] = $base_secure_url;
        $options['absolute'] = TRUE;
      }
      elseif ($options['https'] === FALSE) {
        $options['base_url'] = $base_insecure_url;
        $options['absolute'] = TRUE;
      }
    }
    else {
      $options['base_url'] = $base_url;
    }
  }

  // The special path '<front>' links to the default front page.
  if ($path == '<front>') {
    $path = '';
  }
  elseif (!empty($path) && !$options['alias']) {
    $language = isset($options['language']) && isset($options['language']->language) ? $options['language']->language : '';
    $alias = drupal_get_path_alias($original_path, $language);
    if ($alias != $original_path) {
      $path = $alias;
    }
  }

  $base = $options['absolute'] ? $options['base_url'] . '/' : base_path();
  $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];

  // With Clean URLs.
  if (!empty($GLOBALS['conf']['clean_url'])) {
    $path = drupal_encode_path($prefix . $path);
    if ($options['query']) {
      return $base . $path . '?' . drupal_http_build_query($options['query']) . $options['fragment'];
    }
    else {
      return $base . $path . $options['fragment'];
    }
  }
  // Without Clean URLs.
  else {
    $path = $prefix . $path;
    $query = array();
    if (!empty($path)) {
      $query['q'] = $path;
    }
    if ($options['query']) {
      // We do not use array_merge() here to prevent overriding $path via query
      // parameters.
      $query += $options['query'];
    }
    if ($query) {
      return $base . $script . '?' . drupal_http_build_query($query) . $options['fragment'];
    }
    else {
      return $base . $options['fragment'];
    }
  }
}
?>