Rename static to staticpublisher.

This commit is contained in:
Will Rossiter 2012-09-25 20:02:26 +12:00
parent 9ad7892e08
commit 841ecd9fe5
13 changed files with 97 additions and 76 deletions

View File

@ -1,9 +1,9 @@
# Static
# StaticPublisher
## Introduction
Static provides several extensions for exporting a SilverStripe application to
both local or remote file systems.
This module provides an extension for exporting a SilverStripe application as
static files to both a local or remote server for increased site performance.
## Maintainer Contact
@ -17,6 +17,6 @@ both local or remote file systems.
## Documentation
See docs/
See the docs folder.
Note this is untested on Windows.

View File

@ -4,7 +4,7 @@
* This is a system-generated PHP script that performs header management for
* the statically cached content given below.
*
* @package static
* @package staticpublisher
*/
define('MAX_AGE', '**MAX_AGE**');

View File

@ -4,7 +4,7 @@
* This is a system-generated PHP script that performs header management for
* a 301 redirection.
*
* @package static
* @package staticpublisher
*/
define('DESTINATION', '**DESTINATION**');

View File

@ -12,7 +12,7 @@
*
* @see StaticPublisher
*
* @package static
* @package staticpublisher
*/
class StaticExporter extends Controller {

View File

@ -1,19 +1,7 @@
<?php
/**
* Usage: Object::add_extension("SiteTree", "FilesystemPublisher('static-folder', 'html')");
*
* Usage: To work with Subsite module you need to:
* - Add FilesystemPublisher::$domain_based_caching = true; in mysite/_config.php
* - Added main site host mapping in subsites/host-map.php after everytime a new subsite is created or modified
*
* You may also have a method $page->pagesAffectedByUnpublishing() to return other URLS
* that should be de-cached if $page is unpublished.
*
* @see http://doc.silverstripe.com/doku.php?id=staticpublisher
*
* @package cms
* @subpackage publishers
* @package staticpublisher
*/
class FilesystemPublisher extends StaticPublisher {

View File

@ -1,17 +1,20 @@
<?php
/**
* This static publisher can be used to deploy static content to multiple hosts, by generating the cache files locally and then rsyncing then to
* each destination box. This can be used to set up a load-balanced collection of static servers.
*
* @see http://doc.silverstripe.com/doku.php?id=staticpublisher
* This static publisher can be used to deploy static content to multiple
* hosts, by generating the cache files locally and then rsyncing then to
* each destination box. This can be used to set up a load-balanced
* collection of static servers.
*
* @package cms
* @subpackage publishers
* @package staticpublisher
*/
class RsyncMultiHostPublisher extends FilesystemPublisher {
/**
* Array of rsync targets to publish to. These can either be local file names, or scp-style targets, in the form "user@server:path"
* Array of rsync targets to publish to. These can either be local
* file names, or scp-style targets, in the form "user@server:path"
*
* @var array
*/
protected static $targets = array();
@ -19,25 +22,34 @@ class RsyncMultiHostPublisher extends FilesystemPublisher {
/**
* Set the targets to publish to.
* If target is an scp-style remote path, no password is accepted - we assume key-based authentication to be set up on the application server
*
* If target is an scp-style remote path, no password is accepted - we
* assume key-based authentication to be set up on the application server
* initiating the publication.
*
* @param $targets An array of targets to publish to. These can either be local file names, or scp-style targets, in the form "user@server:path"
* @param $targets An array of targets to publish to. These can either
* be local file names, or scp-style targets, in the form "user@server:path"
*/
static function set_targets($targets) {
public static function set_targets($targets) {
self::$targets = $targets;
}
/**
* Specify folders to exclude from the rsync
* For example, you could exclude assets.
* Specify folders to exclude from the rsync. For example, you could
* exclude assets.
*
* @param array
*/
static function set_excluded_folders($folders) {
public static function set_excluded_folders($folders) {
self::$excluded_folders = $folders;
}
function publishPages($urls) {
/**
* @param array
*/
public function publishPages($urls) {
parent::publishPages($urls);
$base = Director::baseFolder();
$framework = FRAMEWORK_DIR;

View File

@ -1,41 +1,63 @@
<?php
/**
* @package cms
* @subpackage publishers
* @package staticpublisher
*/
abstract class StaticPublisher extends DataExtension {
/**
* Defines whether to output information about publishing or not. By
* default, this is off, and should be turned on when you want debugging
* (for example, in a cron task)
* (for example, in a cron task).
*
* @var boolean
*/
static $echo_progress = false;
protected static $echo_progress = false;
/**
* Realtime static publishing... the second a page
* is saved, it is written to the cache
* Realtime static publishing... the second a page is saved, it is
* written to the cache.
*
* @var boolean
*/
static $disable_realtime = false;
public static $disable_realtime = false;
/*
* This is the current static publishing theme, which can be set at any point
* If it's not set, then the last non-null theme, set via SSViewer::set_theme() is used
* The obvious place to set this is in _config.php
/**
* This is the current static publishing theme, which can be set at any
* point. If it's not set, then the last non-null theme, set via
* SSViewer::set_theme() is used. The obvious place to set this is in
* _config.php
*
* @var string
*/
static $static_publisher_theme=false;
protected static $static_publisher_theme=false;
/**
* @param array
*/
abstract function publishPages($pages);
/**
* @param array
*/
abstract function unpublishPages($pages);
static function set_static_publisher_theme($theme){
/**
* @param string
*/
public static function set_static_publisher_theme($theme) {
self::$static_publisher_theme=$theme;
}
static function static_publisher_theme(){
/**
* @return string
*/
public static function static_publisher_theme() {
return self::$static_publisher_theme;
}
static function echo_progress() {
/**
* @return boolean
*/
public static function echo_progress() {
return (boolean)self::$echo_progress;
}
@ -43,28 +65,30 @@ abstract class StaticPublisher extends DataExtension {
* Either turns on (boolean true) or off (boolean false) the progress indicators.
* @see StaticPublisher::$echo_progress
*/
static function set_echo_progress($progress) {
public static function set_echo_progress($progress) {
self::$echo_progress = (boolean)$progress;
}
/**
* Called after a page is published.
*
* @param SiteTree
*/
function onAfterPublish($original) {
public function onAfterPublish($original) {
$this->republish($original);
}
/**
* Called after link assets have been renamed, and the live site has been updated, without
* an actual publish event.
* Called after link assets have been renamed, and the live site has been
* updated, without an actual publish event.
*
* Only called if the published content exists and has been modified.
*/
function onRenameLinkedAsset($original) {
public function onRenameLinkedAsset($original) {
$this->republish($original);
}
function republish($original) {
public function republish($original) {
if (self::$disable_realtime) return;
$urls = array();
@ -99,10 +123,9 @@ abstract class StaticPublisher extends DataExtension {
}
/**
* On after unpublish, get changes and hook into underlying
* functionality
* Get changes and hook into underlying functionality.
*/
function onAfterUnpublish($page) {
public function onAfterUnpublish($page) {
if (self::$disable_realtime) return;
// Get the affected URLs
@ -125,12 +148,11 @@ abstract class StaticPublisher extends DataExtension {
/**
* Get all external references to CSS, JS,
*/
function externalReferencesFor($content) {
public function externalReferencesFor($content) {
$CLI_content = escapeshellarg($content);
$tidy = `echo $CLI_content | tidy -numeric -asxhtml`;
$tidy = preg_replace('/xmlns="[^"]+"/','', $tidy);
$xContent = new SimpleXMLElement($tidy);
//Debug::message($xContent->asXML());
$xlinks = array(
"//link[@rel='stylesheet']/@href" => false,
@ -140,6 +162,7 @@ abstract class StaticPublisher extends DataExtension {
);
$urls = array();
foreach($xlinks as $xlink => $assetsOnly) {
$matches = $xContent->xpath($xlink);
if($matches) foreach($matches as $item) {
@ -152,6 +175,4 @@ abstract class StaticPublisher extends DataExtension {
return $urls;
}
}
}

View File

@ -177,7 +177,7 @@ your dev environment).
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* static/code/main.php?url=%1&%{QUERY_STRING} [L]
RewriteRule .* staticpublisher/code/main.php?url=%1&%{QUERY_STRING} [L]
### SILVERSTRIPE END ###
@ -190,7 +190,7 @@ Just look for this line:
And change the PHP script from main.php to static-main.php:
RewriteRule .* static/code/main.php?url=%1&%{QUERY_STRING} [L]
RewriteRule .* staticpublisher/code/main.php?url=%1&%{QUERY_STRING} [L]
## Using Static Publisher With Subsites Module

View File

@ -1,10 +1,10 @@
# Static
# StaticPublisher
Static is a module providing extensions to SilverStripe to allow developers to
generate static exports of their SilverStripe sites either for performance or
as a backup system.
StaticPublisher is a module providing an extension to SilverStripe to allow
developers to generate static exports of their SilverStripe sites either
for performance or as a backup system.
There are two main parts to the module
There are two extensions provided by the module:
## Static Publisher

View File

@ -2,7 +2,7 @@
/**
* This file is designed to be the new 'server' of sites using StaticPublisher.
* to use this, you need to modify your .htaccess to point all requests to
* static/main.php, rather than framework/main.php. This file also allows for
* staticpublisher/main.php, rather than framework/main.php. This file also allows for
* using static publisher with the subsites module.
*
* If you are using StaticPublisher+Subsites, set the following in _config.php:
@ -18,7 +18,7 @@
* automatically generated by the Subsites module) and the cache will default
* to no subdirectory.
*
* @package static
* @package staticpublisher
*/
$cacheEnabled = true;
@ -48,7 +48,7 @@ if (
) {
// Define system paths (copied from Core.php)
if(!defined('BASE_PATH')) {
// Assuming that this file is static/main.php we can then determine the base path
// Assuming that this file is staticpublisher/main.php we can then determine the base path
define('BASE_PATH', rtrim(dirname(dirname(__FILE__))), DIRECTORY_SEPARATOR);
}
if(!defined('BASE_URL')) {

View File

@ -1,6 +1,6 @@
<?php
/**
* @package static
* @package staticpublisher
*/
class RebuildStaticCacheTask extends BuildTask {

View File

@ -1,6 +1,6 @@
<?php
/**
* @package static
* @package staticpublisher
*/
class StaticExporterTask extends BuildTask {

View File

@ -2,7 +2,7 @@
/**
* Tests for the {@link FilesystemPublisher} class.
*
* @package static
* @package staticpublisher
*/
class FilesystemPublisherTest extends SapphireTest {