Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
c318d95e
Commit
c318d95e
authored
12 years ago
by
Chris Leppanen
Browse files
Options
Downloads
Patches
Plain Diff
Fix doc strings.
parent
b83c0967
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/http_request.inc
+37
-25
37 additions, 25 deletions
libraries/http_request.inc
with
37 additions
and
25 deletions
libraries/http_request.inc
+
37
−
25
View file @
c318d95e
...
@@ -4,7 +4,8 @@
...
@@ -4,7 +4,8 @@
* @file
* @file
* Download via HTTP.
* Download via HTTP.
*
*
* Support caching, HTTP Basic Authentication, detection of RSS/Atom feeds, redirects.
* Support caching, HTTP Basic Authentication, detection of RSS/Atom feeds,
* redirects.
*/
*/
/**
/**
...
@@ -26,9 +27,14 @@ class HRCurlException extends Exception {}
...
@@ -26,9 +27,14 @@ class HRCurlException extends Exception {}
* Discover RSS or atom feeds at the given URL. If document in given URL is an
* Discover RSS or atom feeds at the given URL. If document in given URL is an
* HTML document, function attempts to discover RSS or Atom feeds.
* HTML document, function attempts to discover RSS or Atom feeds.
*
*
* @param $url
* @param string $url
* @param null $settings
* The url of the feed to retrieve.
* @return bool|string string - the discovered feed, FALSE - if the URL is not reachable or there
* @param array $settings
* An optional array of settings. Valid options are: accept_invalid_cert.
*
* @return bool|string
* The discovered feed, or FALSE if the URL is not reachable or there was an
* error.
*/
*/
function
http_request_get_common_syndication
(
$url
,
$settings
=
NULL
)
{
function
http_request_get_common_syndication
(
$url
,
$settings
=
NULL
)
{
...
@@ -63,16 +69,26 @@ function http_request_get_common_syndication($url, $settings = NULL) {
...
@@ -63,16 +69,26 @@ function http_request_get_common_syndication($url, $settings = NULL) {
/**
/**
* Get the content from the given URL.
* Get the content from the given URL.
*
*
* @param $url
* @param
string
$url
* A valid URL (not only web URLs).
*
A valid URL (not only web URLs).
* @param $username
* @param
string
$username
* If the URL use authentication,
here you can
supply the username
for this
.
*
If the URL use
s
authentication, supply the username.
* @param $password
* @param
string
$password
* If the URL use authentication,
here you can
supply the password
for this
.
*
If the URL use
s
authentication, supply the password.
* @param bool $accept_invalid_cert
* @param bool $accept_invalid_cert
* @return object A stdClass object that describes the data downloaded from $url. The object's
* Whether to accept invalid certificates.
* @return stdClass
* An object that describes the data downloaded from $url.
*/
*/
function
http_request_get
(
$url
,
$username
=
NULL
,
$password
=
NULL
,
$accept_invalid_cert
=
FALSE
)
{
function
http_request_get
(
$url
,
$username
=
NULL
,
$password
=
NULL
,
$accept_invalid_cert
=
FALSE
)
{
// Intra-pagedownload cache, avoid to download the same content twice within
// one page download (it's possible, compatible and parse calls).
static
$download_cache
=
array
();
if
(
isset
(
$download_cache
[
$url
]))
{
return
$download_cache
[
$url
];
}
if
(
!
$username
&&
valid_url
(
$url
,
TRUE
))
{
if
(
!
$username
&&
valid_url
(
$url
,
TRUE
))
{
// Handle password protected feeds.
// Handle password protected feeds.
$url_parts
=
parse_url
(
$url
);
$url_parts
=
parse_url
(
$url
);
...
@@ -82,12 +98,6 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
...
@@ -82,12 +98,6 @@ function http_request_get($url, $username = NULL, $password = NULL, $accept_inva
}
}
}
}
// Intra-pagedownload cache, avoid to download the same content twice within one page download
// (it's possible, compatible and parse calls).
static
$download_cache
=
array
();
if
(
isset
(
$download_cache
[
$url
]))
{
return
$download_cache
[
$url
];
}
$curl
=
http_request_use_curl
();
$curl
=
http_request_use_curl
();
// Only download and parse data if really needs refresh.
// Only download and parse data if really needs refresh.
...
@@ -275,7 +285,8 @@ function http_request_is_feed($content_type, $data) {
...
@@ -275,7 +285,8 @@ function http_request_is_feed($content_type, $data) {
return
TRUE
;
return
TRUE
;
}
}
// @TODO: Sometimes the content-type can be text/html but still be a valid feed.
// @TODO: Sometimes the content-type can be text/html but still be a valid
// feed.
return
FALSE
;
return
FALSE
;
}
}
...
@@ -301,7 +312,8 @@ function http_request_find_feeds($html) {
...
@@ -301,7 +312,8 @@ function http_request_find_feeds($html) {
preg_match_all
(
HTTP_REQUEST_PCRE_TAG_ATTRIBUTES
,
$link_tag
,
$attributes
,
PREG_SET_ORDER
);
preg_match_all
(
HTTP_REQUEST_PCRE_TAG_ATTRIBUTES
,
$link_tag
,
$attributes
,
PREG_SET_ORDER
);
foreach
(
$attributes
as
$attribute
)
{
foreach
(
$attributes
as
$attribute
)
{
// Find the key value pairs, attribute[1] is key and attribute[2] is the value.
// Find the key value pairs, attribute[1] is key and attribute[2] is the
// value.
if
(
!
empty
(
$attribute
[
1
])
&&
!
empty
(
$attribute
[
2
]))
{
if
(
!
empty
(
$attribute
[
1
])
&&
!
empty
(
$attribute
[
2
]))
{
$candidate
[
drupal_strtolower
(
$attribute
[
1
])]
=
drupal_strtolower
(
decode_entities
(
$attribute
[
2
]));
$candidate
[
drupal_strtolower
(
$attribute
[
1
])]
=
drupal_strtolower
(
decode_entities
(
$attribute
[
2
]));
}
}
...
@@ -324,13 +336,12 @@ function http_request_find_feeds($html) {
...
@@ -324,13 +336,12 @@ function http_request_find_feeds($html) {
* Create an absolute url.
* Create an absolute url.
*
*
* @param string $url
* @param string $url
* The href to transform.
* The href to transform.
*
* @param string $base_url
* @param $base_url
* The url to be used as the base for a relative $url.
* The url to be used as the base for a relative $url.
*
*
* @return string
* @return string
*
a
n absolute url
*
A
n absolute url
*/
*/
function
http_request_create_absolute_url
(
$url
,
$base_url
)
{
function
http_request_create_absolute_url
(
$url
,
$base_url
)
{
$url
=
trim
(
$url
);
$url
=
trim
(
$url
);
...
@@ -341,7 +352,8 @@ function http_request_create_absolute_url($url, $base_url) {
...
@@ -341,7 +352,8 @@ function http_request_create_absolute_url($url, $base_url) {
// Turn relative url into absolute.
// Turn relative url into absolute.
if
(
valid_url
(
$url
,
FALSE
))
{
if
(
valid_url
(
$url
,
FALSE
))
{
// Produces variables $scheme, $host, $user, $pass, $path, $query and $fragment.
// Produces variables $scheme, $host, $user, $pass, $path, $query and
// $fragment.
$parsed_url
=
parse_url
(
$base_url
);
$parsed_url
=
parse_url
(
$base_url
);
$path
=
dirname
(
$parsed_url
[
'path'
]);
$path
=
dirname
(
$parsed_url
[
'path'
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment