~pwolanin/+junk/AD-pressflow-6

« back to all changes in this revision

Viewing changes to includes/common.inc

  • Committer: bzr
  • Date: 2009-01-15 00:30:06 UTC
  • Revision ID: bzr@web3.fourkitchens.com-20090115003006-09rbv04r2gw9bnkd
DrupalĀ 6.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Id: common.inc,v 1.756.2.37 2008/12/11 17:39:42 goba Exp $
 
2
// $Id: common.inc,v 1.756.2.42 2009/01/14 23:34:07 goba Exp $
3
3
 
4
4
/**
5
5
 * @file
414
414
 *   data and redirect status.
415
415
 */
416
416
function drupal_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
417
 
  static $self_test = FALSE;
418
417
  $result = new stdClass();
419
 
  // Try to clear the drupal_http_request_fails variable if it's set. We
420
 
  // can't tie this call to any error because there is no surefire way to
421
 
  // tell whether a request has failed, so we add the check to places where
422
 
  // some parsing has failed.
423
 
  if (!$self_test && variable_get('drupal_http_request_fails', FALSE)) {
424
 
    $self_test = TRUE;
425
 
    $works = module_invoke('system', 'check_http_request');
426
 
    $self_test = FALSE;
427
 
    if (!$works) {
428
 
      // Do not bother with further operations if we already know that we
429
 
      // have no chance.
430
 
      $result->error = t("The server can't issue HTTP requests");
431
 
      return $result;
432
 
    }
433
 
  }
434
418
 
435
419
  // Parse the URL and make sure we can handle the schema.
436
420
  $uri = parse_url($url);
468
452
    // clash with the HTTP status codes.
469
453
    $result->code = -$errno;
470
454
    $result->error = trim($errstr);
 
455
 
 
456
    // Mark that this request failed. This will trigger a check of the web
 
457
    // server's ability to make outgoing HTTP requests the next time that
 
458
    // requirements checking is performed.
 
459
    // @see system_requirements()
 
460
    variable_set('drupal_http_request_fails', TRUE);
 
461
 
471
462
    return $result;
472
463
  }
473
464
 
684
675
 *
685
676
 * Special variables called "placeholders" are used to signal dynamic
686
677
 * information in a string which should not be translated. Placeholders
687
 
 * can also be used for text that may change from time to time
688
 
 * (such as link paths) to be changed without requiring updates to translations.
 
678
 * can also be used for text that may change from time to time (such as
 
679
 * link paths) to be changed without requiring updates to translations.
689
680
 *
690
681
 * For example:
691
682
 * @code
701
692
 *     $message[] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE))));
702
693
 *   @endcode
703
694
 *
704
 
 * - @variable, which indicates that the text should be run through check_plain,
705
 
 *   to escape HTML characters. Use this for any output that's displayed within
706
 
 *   a Drupal page.
 
695
 * - @variable, which indicates that the text should be run through
 
696
 *   check_plain, to escape HTML characters. Use this for any output that's
 
697
 *   displayed within a Drupal page.
707
698
 *   @code
708
699
 *     drupal_set_title($title = t("@name's blog", array('@name' => $account->name)));
709
700
 *   @endcode
716
707
 *   @endcode
717
708
 *
718
709
 * When using t(), try to put entire sentences and strings in one t() call.
719
 
 * This makes it easier for translators, as it provides context as to what each
720
 
 * word refers to. HTML markup within translation strings is allowed, but should
721
 
 * be avoided if possible. The exception are embedded links; link titles add a
722
 
 * context for translators, so should be kept in the main string.
 
710
 * This makes it easier for translators, as it provides context as to what
 
711
 * each word refers to. HTML markup within translation strings is allowed, but
 
712
 * should be avoided if possible. The exception are embedded links; link
 
713
 * titles add a context for translators, so should be kept in the main string.
723
714
 *
724
715
 * Here is an example of incorrect usage of t():
725
716
 * @code
842
833
 *   A string containing the English string to translate.
843
834
 * @param $args
844
835
 *   An associative array of replacements to make after translation. Incidences
845
 
 *   of any key in this array are replaced with the corresponding value.
846
 
 *   Based on the first character of the key, the value is escaped and/or themed:
 
836
 *   of any key in this array are replaced with the corresponding value. Based
 
837
 *   on the first character of the key, the value is escaped and/or themed:
847
838
 *    - !variable: inserted as is
848
839
 *    - @variable: escape plain text to HTML (check_plain)
849
840
 *    - %variable: escape text and theme as a placeholder for user-submitted
931
922
 *
932
923
 * This function should only be used on actual URLs. It should not be used for
933
924
 * Drupal menu paths, which can contain arbitrary characters.
 
925
 * Valid values per RFC 3986.
934
926
 *
935
927
 * @param $url
936
928
 *   The URL to verify.
940
932
 *   TRUE if the URL is in a valid format.
941
933
 */
942
934
function valid_url($url, $absolute = FALSE) {
943
 
  $allowed_characters = '[a-z0-9\/:_\-_\.\?\$,;~=#&%\+]';
944
935
  if ($absolute) {
945
 
    return preg_match("/^(http|https|ftp):\/\/". $allowed_characters ."+$/i", $url);
 
936
    return (bool)preg_match("
 
937
      /^                                                      # Start at the beginning of the text
 
938
      (?:ftp|https?):\/\/                                     # Look for ftp, http, or https schemes
 
939
      (?:                                                     # Userinfo (optional) which is typically
 
940
        (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*      # a username or a username and password
 
941
        (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@          # combination
 
942
      )?
 
943
      (?:
 
944
        (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # A domain name or a IPv4 address
 
945
        |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or a well formed IPv6 address
 
946
      )
 
947
      (?::[0-9]+)?                                            # Server port number (optional)
 
948
      (?:[\/|\?]
 
949
        (?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})   # The path and query (optional)
 
950
      *)?
 
951
    $/xi", $url);
946
952
  }
947
953
  else {
948
 
    return preg_match("/^". $allowed_characters ."+$/i", $url);
 
954
    return (bool)preg_match("/^(?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
949
955
  }
950
956
}
951
957
 
 
958
 
952
959
/**
953
960
 * @} End of "defgroup validation".
954
961
 */