mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT STaticPublisher can now play nice with Subsites, you just need to set FilesystemPublisher::domain_based_caching to true.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@81683 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
92ff4e149b
commit
ac589ba236
@ -14,6 +14,12 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
|
|
||||||
protected static $static_base_url = null;
|
protected static $static_base_url = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use domain based cacheing (put cache files into a domain subfolder)
|
||||||
|
* This must be true if you are using this with subsites.
|
||||||
|
*/
|
||||||
|
public static $domain_based_caching = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a different base URL for the static copy of the site.
|
* Set a different base URL for the static copy of the site.
|
||||||
* This can be useful if you are running the CMS on a different domain from the website.
|
* This can be useful if you are running the CMS on a different domain from the website.
|
||||||
@ -67,15 +73,6 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
Requirements::clear();
|
Requirements::clear();
|
||||||
|
|
||||||
DataObject::flush_and_destroy_cache();
|
DataObject::flush_and_destroy_cache();
|
||||||
//DataObject::destroy_cached_get_calls(false);
|
|
||||||
//DataObject::cache_get_calls(false);
|
|
||||||
|
|
||||||
//echo 'Memory: ' . round(memory_get_usage()/100000)/10 . "\n";
|
|
||||||
/*
|
|
||||||
if(!is_object($response)) {
|
|
||||||
echo "String response for url '$url'\n";
|
|
||||||
print_r($response);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Generate file content
|
// Generate file content
|
||||||
// PHP file caching will generate a simple script from a template
|
// PHP file caching will generate a simple script from a template
|
||||||
@ -105,9 +102,18 @@ class FilesystemPublisher extends StaticPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$urlParts = @parse_url($url);
|
||||||
|
$urlParts['path'] = isset($urlParts['path']) ? $urlParts['path'] : '';
|
||||||
|
$url = preg_replace('/[^a-zA-Z0-9]/si', '_', trim($urlParts['path'], '/'));
|
||||||
|
|
||||||
if($this->fileExtension) $filename = $url ? "$url.$this->fileExtension" : "index.$this->fileExtension";
|
if($this->fileExtension) $filename = $url ? "$url.$this->fileExtension" : "index.$this->fileExtension";
|
||||||
else $filename = $url ? "$url/index.html" : "index.html";
|
else $filename = $url ? "$url/index.html" : "index.html";
|
||||||
|
|
||||||
|
if (self::$domain_based_caching) {
|
||||||
|
if (!$urlParts) continue; // seriously malformed url here...
|
||||||
|
$filename = $urlParts['host'] . '/' . $filename;
|
||||||
|
}
|
||||||
|
|
||||||
$files[$filename] = array(
|
$files[$filename] = array(
|
||||||
'Content' => $content,
|
'Content' => $content,
|
||||||
'Folder' => (dirname($filename) == '/') ? '' : (dirname($filename).'/'),
|
'Folder' => (dirname($filename) == '/') ? '' : (dirname($filename).'/'),
|
||||||
|
@ -34,7 +34,7 @@ abstract class StaticPublisher extends DataObjectDecorator {
|
|||||||
$pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
|
$pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
|
||||||
if($pages) {
|
if($pages) {
|
||||||
foreach($pages as $page) {
|
foreach($pages as $page) {
|
||||||
$urls[] = $page->Link();
|
$urls[] = $page->AbsoluteLink();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +44,6 @@ abstract class StaticPublisher extends DataObjectDecorator {
|
|||||||
user_error("Bad URL: " . var_export($url, true), E_USER_WARNING);
|
user_error("Bad URL: " . var_export($url, true), E_USER_WARNING);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$url = Director::makeRelative($url);
|
|
||||||
if(substr($url,-1) == '/') $url = substr($url,0,-1);
|
if(substr($url,-1) == '/') $url = substr($url,0,-1);
|
||||||
$urls[$i] = $url;
|
$urls[$i] = $url;
|
||||||
}
|
}
|
||||||
|
@ -49,15 +49,9 @@ class RebuildStaticCacheTask extends Controller {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = Director::makeRelative($url);
|
|
||||||
// Exclude absolute links
|
|
||||||
if(preg_match('/^https?:/', $url)) {
|
|
||||||
unset($urls[$i]);
|
|
||||||
} else {
|
|
||||||
if(substr($url,-1) == '/') $url = substr($url,0,-1);
|
if(substr($url,-1) == '/') $url = substr($url,0,-1);
|
||||||
$urls[$i] = $url;
|
$urls[$i] = $url;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$urls = array_unique($urls);
|
$urls = array_unique($urls);
|
||||||
sort($urls);
|
sort($urls);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user