Skip to content

Commit

Permalink
Fixed support for protocol relative remote urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
aelvan committed Oct 6, 2018
1 parent 8f4b314 commit 07a1c05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Inlin Changelog

## 2.1.1 - 2018-10-06
### Fixed
- Fixed support for protocol relative remote urls (Thanks, @joshuabaker).

## 2.1.0 - 2018-10-06
### Added
- Inlin now uses `@webroot` alias instead of $_SERVER\['DOCUMENT_ROOT'\] as path root by default.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "aelvan/inlin",
"description": "A simple plugin for inlining stuff in your templates.",
"type": "craft-plugin",
"version": "2.1.0",
"version": "2.1.1",
"keywords": [
"craft",
"cms",
Expand Down
13 changes: 8 additions & 5 deletions src/variables/InlinVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ class InlinVariable
*/
public function er($fileName, $remote = false): string
{
$documentRoot = \Yii::getAlias(Inlin::getInstance()->getSettings()->publicRoot ?? '@webroot');
$filePath = $this->_removeDoubleSlashes($documentRoot.'/'.$fileName);

if ($remote) {
$content = @file_get_contents($fileName);
if (strpos($fileName, '//') === 0) {
$protocol = \Craft::$app->request->isSecureConnection ? 'https:' : 'http:';
$fileName = $protocol.$fileName;
}

return $content;
return @file_get_contents($fileName);
}

$documentRoot = \Yii::getAlias(Inlin::getInstance()->getSettings()->publicRoot ?? '@webroot');
$filePath = $this->_removeDoubleSlashes($documentRoot.'/'.$fileName);

if ($fileName !== '' && file_exists($filePath)) {
$content = @file_get_contents($filePath);

Expand Down

0 comments on commit 07a1c05

Please sign in to comment.