Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

[91] - switching the patterns in the MediaInternetGovCmsCkanHandler->… #93

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MediaInternetGovCmsCkanHandler extends MediaInternetBaseHandler {

protected $baseUrl;
protected $baseHost;
protected $basePath;
protected $baseUri = 'ckan://resource/';

/**
Expand All @@ -22,6 +23,7 @@ class MediaInternetGovCmsCkanHandler extends MediaInternetBaseHandler {
parent::__construct($embed_code);
$this->baseUrl = variable_get('govcms_ckan_endpoint_url', '');
$this->baseHost = $this->getBaseHost();
$this->basePath = $this->getBasePath();
}

/**
Expand All @@ -34,8 +36,8 @@ class MediaInternetGovCmsCkanHandler extends MediaInternetBaseHandler {
// @baseurl/dataset/PACKAGE_ID/resource/RESOURCE_ID/download/filename.csv
// @baseurl/dataset/PACKAGE_ID/resource/RESOURCE_ID
$patterns = array(
'@' . $this->baseHost . '/dataset/([^"\&\? ]+)/resource/([^"\&\? ]+)/download/(?:[^"\&\? ]+)@i',
'@' . $this->baseHost . '/dataset/([^"\&\? ]+)/resource/([^"\&\? ]+)@i',
'@' . $this->baseHost . $this->basePath . '/dataset/([^"\&\? ]+)/resource/([^"\&\? ]+)/download/(?:[^"\&\? ]+)@i',
'@' . $this->baseHost . $this->basePath . '/dataset/([^"\&\? ]+)/resource/([^"\&\? ]+)@i',
);

// First check if the url contains the embed code.
Expand Down Expand Up @@ -185,6 +187,17 @@ class MediaInternetGovCmsCkanHandler extends MediaInternetBaseHandler {
return (!empty($url_parts['host']) ? $url_parts['host'] . $port : NULL);
}

/**
* Get the base path.
*
* @return string
* If valid path found it is returned, otherwise an empty string.
*/
public function getBasePath() {
$url_parts = parse_url($this->baseUrl);
return (!empty($url_parts['path']) ? $url_parts['path'] : '');
}

/**
* Build a resource url.
*
Expand Down