2016-08-16 03:22:58 +02:00
|
|
|
<?php
|
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Model\RedirectorPage;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2016-09-08 09:33:32 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2016-08-16 03:22:58 +02:00
|
|
|
use SilverStripe\ORM\Versioning\Versioned;
|
|
|
|
|
|
|
|
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
|
|
|
|
{
|
|
|
|
/** @config */
|
|
|
|
private static $priority = 30;
|
|
|
|
|
|
|
|
public function getHTML()
|
|
|
|
{
|
|
|
|
$livePage = $this->getLivePage();
|
2016-09-07 11:24:30 +02:00
|
|
|
if (!$livePage) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$linkClass = $this->isActive() ? 'class="current" ' : '';
|
|
|
|
$linkTitle = _t('ContentController.PUBLISHEDSITE', 'Published Site');
|
|
|
|
$recordLink = Convert::raw2att(Controller::join_links($livePage->AbsoluteLink(), "?stage=Live"));
|
|
|
|
return "<a {$linkClass} href=\"$recordLink\">$linkTitle</a>";
|
2016-08-16 03:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return _t('ContentController.PUBLISHED', 'Published',
|
|
|
|
'Used for the Switch between draft and published view mode. Needs to be a short label');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMessage()
|
|
|
|
{
|
|
|
|
return "<div id=\"SilverStripeNavigatorMessage\" title=\"" . _t('ContentControl.NOTEWONTBESHOWN',
|
|
|
|
'Note: this message will not be shown to your visitors') . "\">" . _t('ContentController.PUBLISHEDSITE',
|
|
|
|
'Published Site') . "</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLink()
|
|
|
|
{
|
|
|
|
return Controller::join_links($this->record->PreviewLink(), '?stage=Live');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
$this->record->hasExtension('SilverStripe\ORM\Versioning\Versioned')
|
|
|
|
&& $this->getLivePage()
|
|
|
|
// Don't follow redirects in preview, they break the CMS editing form
|
|
|
|
&& !($this->record instanceof RedirectorPage)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isActive()
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(!Versioned::get_stage() || Versioned::get_stage() == 'Live')
|
|
|
|
&& !$this->isArchived()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getLivePage()
|
|
|
|
{
|
|
|
|
$baseClass = $this->record->baseClass();
|
|
|
|
return Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
|
|
|
|
}
|
|
|
|
}
|