Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion src/nlac/NLSClientScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class NLSClientScript extends \CClientScript {
/**
* @param string $appVersion
* Optional, version of the application.
* Set 'auto' will allow auto regenerate when source changed
* If set to not empty, will be appended to the merged js/css urls (helps to handle cached resources).
**/
public $appVersion = '';
Expand Down Expand Up @@ -188,10 +189,16 @@ class NLSClientScript extends \CClientScript {
protected $cssMerger = null;


protected $isAutoAppVersion = false;

public function init() {
parent::init();

if ($this->appVersion == 'auto'){
$this->isAutoAppVersion = true;
$this->appVersion = 0;
}

if (is_numeric($this->nlsScriptPosition))
//-> we need jquery
$this->registerCoreScript('jquery');
Expand Down Expand Up @@ -224,6 +231,14 @@ public function init() {
}

protected function addAppVersion($url) {
// if auto version flag is set (appVersion='auto')
// get file modified time and use as version before hashing
if ($this->isAutoAppVersion && !NLSUtils::isAbsoluteUrl($url)) {
$ver = NLSUtils::getFileMTime($url);
$this->appVersion = max($this->appVersion, $ver);
return NLSUtils::addUrlParams($url, array('nlsver' => $ver));
}
// original none auto
if (!empty($this->appVersion) && !NLSUtils::isAbsoluteUrl($url))
$url = NLSUtils::addUrlParams($url, array('nlsver' => $this->appVersion));
return $url;
Expand Down Expand Up @@ -478,4 +493,5 @@ protected function _putnlscode() {

$this->registerScript('fixDuplicateResources', $js, $this->nlsScriptPosition);
}
}

}
8 changes: 7 additions & 1 deletion src/nlac/NLSUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ public static function addUrlParams($url, $params) {
public static function isAbsoluteUrl($url) {
return preg_match('@^https?://@', $url);
}

public static function getFileMTime($path){
// append doc root and remove trailing
$path = $_SERVER['DOCUMENT_ROOT'].preg_replace('@[\?#].*$@', '', $path);
return file_exists($path) ? filemtime($path) : 0;
}

}
}