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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,7 @@
<?php <?php
/** /**
* Usage: Object::add_extension("SiteTree", "FilesystemPublisher('static-folder', 'html')"); * @package staticpublisher
*
* 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
*/ */
class FilesystemPublisher extends StaticPublisher { class FilesystemPublisher extends StaticPublisher {

View File

@ -1,17 +1,20 @@
<?php <?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 * This static publisher can be used to deploy static content to multiple
* each destination box. This can be used to set up a load-balanced collection of static servers. * 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
* @see http://doc.silverstripe.com/doku.php?id=staticpublisher * collection of static servers.
* *
* @package cms * @package staticpublisher
* @subpackage publishers
*/ */
class RsyncMultiHostPublisher extends FilesystemPublisher { 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(); protected static $targets = array();
@ -19,25 +22,34 @@ class RsyncMultiHostPublisher extends FilesystemPublisher {
/** /**
* Set the targets to publish to. * 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. * 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; self::$targets = $targets;
} }
/** /**
* Specify folders to exclude from the rsync * Specify folders to exclude from the rsync. For example, you could
* For example, you could exclude assets. * exclude assets.
*
* @param array
*/ */
static function set_excluded_folders($folders) { public static function set_excluded_folders($folders) {
self::$excluded_folders = $folders; self::$excluded_folders = $folders;
} }
function publishPages($urls) { /**
* @param array
*/
public function publishPages($urls) {
parent::publishPages($urls); parent::publishPages($urls);
$base = Director::baseFolder(); $base = Director::baseFolder();
$framework = FRAMEWORK_DIR; $framework = FRAMEWORK_DIR;

View File

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

View File

@ -177,7 +177,7 @@ your dev environment).
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_URI} ^(.*)$ RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f 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 ### ### SILVERSTRIPE END ###
@ -190,7 +190,7 @@ Just look for this line:
And change the PHP script from main.php to static-main.php: 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 ## 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 StaticPublisher is a module providing an extension to SilverStripe to allow
generate static exports of their SilverStripe sites either for performance or developers to generate static exports of their SilverStripe sites either
as a backup system. 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 ## Static Publisher

View File

@ -2,7 +2,7 @@
/** /**
* This file is designed to be the new 'server' of sites using StaticPublisher. * 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 * 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. * using static publisher with the subsites module.
* *
* If you are using StaticPublisher+Subsites, set the following in _config.php: * 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 * automatically generated by the Subsites module) and the cache will default
* to no subdirectory. * to no subdirectory.
* *
* @package static * @package staticpublisher
*/ */
$cacheEnabled = true; $cacheEnabled = true;
@ -48,7 +48,7 @@ if (
) { ) {
// Define system paths (copied from Core.php) // Define system paths (copied from Core.php)
if(!defined('BASE_PATH')) { 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); define('BASE_PATH', rtrim(dirname(dirname(__FILE__))), DIRECTORY_SEPARATOR);
} }
if(!defined('BASE_URL')) { if(!defined('BASE_URL')) {

View File

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

View File

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

View File

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