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:
Tom Rix 2009-07-13 04:42:02 +00:00
parent 92ff4e149b
commit ac589ba236
3 changed files with 21 additions and 22 deletions

View File

@ -14,6 +14,12 @@ class FilesystemPublisher extends StaticPublisher {
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.
* This can be useful if you are running the CMS on a different domain from the website.
@ -67,16 +73,7 @@ class FilesystemPublisher extends StaticPublisher {
Requirements::clear();
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
// PHP file caching will generate a simple script from a template
if($this->fileExtension == 'php') {
@ -103,11 +100,20 @@ class FilesystemPublisher extends StaticPublisher {
$content = $response . '';
}
}
$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";
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(
'Content' => $content,
'Folder' => (dirname($filename) == '/') ? '' : (dirname($filename).'/'),

View File

@ -34,7 +34,7 @@ abstract class StaticPublisher extends DataObjectDecorator {
$pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
if($pages) {
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);
continue;
}
$url = Director::makeRelative($url);
if(substr($url,-1) == '/') $url = substr($url,0,-1);
$urls[$i] = $url;
}

View File

@ -49,14 +49,8 @@ class RebuildStaticCacheTask extends Controller {
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);
$urls[$i] = $url;
}
if(substr($url,-1) == '/') $url = substr($url,0,-1);
$urls[$i] = $url;
}
$urls = array_unique($urls);
sort($urls);