mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR ajshort: Deprecated un-used HTTPResponse->getLinks() method that duplicated functionality.
From: Andrew Short <andrewjshort@gmail.com> git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88467 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
84ec644448
commit
d81d7593b3
@ -210,27 +210,28 @@ class HTTPResponse extends Object {
|
||||
return in_array($this->statusCode, array(301, 302, 401, 403));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the links in the body as an array.
|
||||
* @returns An array of maps. Each map will contain 'id', 'class', and 'href', representing the HTML attributes of the link.
|
||||
*/
|
||||
function getLinks() {
|
||||
$attributes = array('id', 'href', 'class');
|
||||
$links = array();
|
||||
$results = array();
|
||||
/**
|
||||
* @deprecated 2.4 Use {@link HTTP::getLinksIn()} on DOMDocument.
|
||||
*/
|
||||
public function getLinks() {
|
||||
user_error (
|
||||
'HTTPResponse->getLinks() is deprecated, please use HTTP::getLinksIn() or DOMDocument.', E_USER_NOTICE
|
||||
);
|
||||
|
||||
preg_match_all('/<a[^>]+>/i', $this->body, $links);
|
||||
// $links[0] contains the actual matches
|
||||
foreach($links[0] as $link) {
|
||||
$attributes = array('id', 'href', 'class');
|
||||
$links = array();
|
||||
$results = array();
|
||||
|
||||
if(preg_match_all('/<a[^>]+>/i', $this->body, $links)) foreach($links[0] as $link) {
|
||||
$processedLink = array();
|
||||
foreach($attributes as $attribute) {
|
||||
$matches = array();
|
||||
if(preg_match('/' . $attribute . '\s*=\s*"([^"]+)"/i', $link, $matches)) {
|
||||
$processedLink[$attribute] = $matches[1];
|
||||
}
|
||||
}
|
||||
foreach($attributes as $attribute) {
|
||||
$matches = array();
|
||||
if(preg_match('/' . $attribute . '\s*=\s*"([^"]+)"/i', $link, $matches)) {
|
||||
$processedLink[$attribute] = $matches[1];
|
||||
}
|
||||
}
|
||||
$results[] = $processedLink;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user