2008-08-12 04:59:27 +02:00
|
|
|
<?php
|
2009-02-04 21:18:12 +01:00
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage publishers
|
|
|
|
*/
|
2008-08-12 04:59:27 +02:00
|
|
|
abstract class StaticPublisher extends DataObjectDecorator {
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
static $echo_progress = false;
|
|
|
|
|
|
|
|
abstract function publishPages($pages);
|
2009-07-23 00:57:02 +02:00
|
|
|
abstract function unpublishPages($pages);
|
2008-08-12 04:59:27 +02:00
|
|
|
|
|
|
|
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) {
|
|
|
|
self::$echo_progress = (boolean)$progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAfterPublish($original) {
|
2009-04-06 03:28:03 +02:00
|
|
|
$urls = array();
|
|
|
|
|
2008-08-12 04:59:27 +02:00
|
|
|
if($this->owner->hasMethod('pagesAffectedByChanges')) {
|
|
|
|
$urls = $this->owner->pagesAffectedByChanges($original);
|
|
|
|
} else {
|
2009-04-06 03:28:03 +02:00
|
|
|
$pages = Versioned::get_by_stage('SiteTree', 'Live', '', '', '', 10);
|
|
|
|
if($pages) {
|
|
|
|
foreach($pages as $page) {
|
2009-07-13 06:42:02 +02:00
|
|
|
$urls[] = $page->AbsoluteLink();
|
2009-04-06 03:28:03 +02:00
|
|
|
}
|
2008-08-12 04:59:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($urls as $i => $url) {
|
2008-12-15 02:31:01 +01:00
|
|
|
if(!is_string($url)) {
|
|
|
|
user_error("Bad URL: " . var_export($url, true), E_USER_WARNING);
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-12 04:59:27 +02:00
|
|
|
if(substr($url,-1) == '/') $url = substr($url,0,-1);
|
|
|
|
$urls[$i] = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
$urls = array_unique($urls);
|
|
|
|
|
|
|
|
$this->publishPages($urls);
|
|
|
|
}
|
2009-07-23 00:57:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On after unpublish, get changes and hook into underlying
|
|
|
|
* functionality
|
|
|
|
*/
|
|
|
|
function onAfterUnpublish($page) {
|
|
|
|
if($this->owner->hasMethod('pagesAffectedByUnpublishing')) {
|
|
|
|
$urls = $this->owner->pagesAffectedByUnpublishing();
|
|
|
|
$urls = array_unique($urls);
|
|
|
|
} else {
|
|
|
|
$urls = array($this->owner->AbsoluteLink());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->unpublishPages($urls);
|
|
|
|
}
|
2008-08-12 04:59:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all external references to CSS, JS,
|
|
|
|
*/
|
|
|
|
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,
|
|
|
|
"//script/@src" => false,
|
|
|
|
"//img/@src" => false,
|
|
|
|
"//a/@href" => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
$urls = array();
|
|
|
|
foreach($xlinks as $xlink => $assetsOnly) {
|
|
|
|
$matches = $xContent->xpath($xlink);
|
|
|
|
if($matches) foreach($matches as $item) {
|
|
|
|
$url = $item . '';
|
|
|
|
if($assetsOnly && substr($url,0,7) != 'assets/') continue;
|
|
|
|
|
|
|
|
$urls[] = $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $urls;
|
|
|
|
}
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
2008-12-15 02:31:01 +01:00
|
|
|
?>
|