Skip to content

Commit

Permalink
Rename static to staticpublisher.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Sep 25, 2012
1 parent 9ad7892 commit 841ecd9
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 76 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -17,6 +17,6 @@ both local or remote file systems.

## Documentation

See docs/
See the docs folder.

Note this is untested on Windows.
2 changes: 1 addition & 1 deletion code/CachedPHPPage.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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**');
Expand Down
2 changes: 1 addition & 1 deletion code/CachedPHPRedirection.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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**');
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/StaticExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @see StaticPublisher
*
* @package static
* @package staticpublisher
*/
class StaticExporter extends Controller {

Expand Down
14 changes: 1 addition & 13 deletions code/extensions/FilesystemPublisher.php
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
40 changes: 26 additions & 14 deletions code/extensions/RsyncMultiHostPublisher.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
<?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();

protected static $excluded_folders = array();

/**
* 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;

Expand Down
79 changes: 50 additions & 29 deletions code/extensions/StaticPublisher.php
Original file line number Diff line number Diff line change
@@ -1,70 +1,94 @@
<?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;
}

/**
* 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();
Expand Down Expand Up @@ -99,10 +123,9 @@ function republish($original) {
}

/**
* 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
Expand All @@ -125,12 +148,11 @@ function onAfterUnpublish($page) {
/**
* 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,
Expand All @@ -140,6 +162,7 @@ function externalReferencesFor($content) {
);

$urls = array();

foreach($xlinks as $xlink => $assetsOnly) {
$matches = $xContent->xpath($xlink);
if($matches) foreach($matches as $item) {
Expand All @@ -152,6 +175,4 @@ function externalReferencesFor($content) {

return $urls;
}

}

}
4 changes: 2 additions & 2 deletions docs/en/StaticPublisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###


Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions docs/en/index.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -18,7 +18,7 @@
* automatically generated by the Subsites module) and the cache will default
* to no subdirectory.
*
* @package static
* @package staticpublisher
*/

$cacheEnabled = true;
Expand Down Expand Up @@ -48,7 +48,7 @@ function skipCache() {
) {
// 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')) {
Expand Down
2 changes: 1 addition & 1 deletion tasks/RebuildStaticCacheTask.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package static
* @package staticpublisher
*/
class RebuildStaticCacheTask extends BuildTask {

Expand Down
2 changes: 1 addition & 1 deletion tasks/StaticExporterTask.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @package static
* @package staticpublisher
*/
class StaticExporterTask extends BuildTask {

Expand Down
2 changes: 1 addition & 1 deletion tests/FilesystemPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Tests for the {@link FilesystemPublisher} class.
*
* @package static
* @package staticpublisher
*/
class FilesystemPublisherTest extends SapphireTest {

Expand Down

0 comments on commit 841ecd9

Please sign in to comment.