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;
|
2019-10-30 10:02:18 +01:00
|
|
|
use SilverStripe\Core\Config\Config;
|
2016-09-08 09:33:32 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2018-02-19 23:03:23 +01:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-03-21 05:26:46 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-16 03:22:58 +02:00
|
|
|
|
|
|
|
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
|
|
|
|
{
|
2017-01-25 21:59:25 +01:00
|
|
|
/** @config */
|
|
|
|
private static $priority = 30;
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function getHTML()
|
|
|
|
{
|
|
|
|
$livePage = $this->getLivePage();
|
2016-09-07 11:24:30 +02:00
|
|
|
if (!$livePage) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$linkClass = $this->isActive() ? 'class="current" ' : '';
|
2017-04-20 03:15:29 +02:00
|
|
|
$linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHEDSITE', 'Published Site');
|
2016-09-07 11:24:30 +02:00
|
|
|
$recordLink = Convert::raw2att(Controller::join_links($livePage->AbsoluteLink(), "?stage=Live"));
|
|
|
|
return "<a {$linkClass} href=\"$recordLink\">$linkTitle</a>";
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return _t(
|
2017-04-20 03:15:29 +02:00
|
|
|
'SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHED',
|
2017-01-25 21:59:25 +01:00
|
|
|
'Published',
|
|
|
|
'Used for the Switch between draft and published view mode. Needs to be a short label'
|
|
|
|
);
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function getMessage()
|
|
|
|
{
|
|
|
|
return "<div id=\"SilverStripeNavigatorMessage\" title=\"" . _t(
|
2017-04-20 03:45:23 +02:00
|
|
|
'SilverStripe\\CMS\\Controllers\\ContentController.NOTEWONTBESHOWN',
|
2017-01-25 21:59:25 +01:00
|
|
|
'Note: this message will not be shown to your visitors'
|
|
|
|
) . "\">" . _t(
|
2017-04-20 03:15:29 +02:00
|
|
|
'SilverStripe\\CMS\\Controllers\\ContentController.PUBLISHEDSITE',
|
2017-01-25 21:59:25 +01:00
|
|
|
'Published Site'
|
|
|
|
) . "</div>";
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function getLink()
|
|
|
|
{
|
2018-10-06 21:32:58 +02:00
|
|
|
return Controller::join_links($this->getLivePage()->PreviewLink(), '?stage=Live');
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function canView($member = null)
|
|
|
|
{
|
2018-02-19 23:03:23 +01:00
|
|
|
/** @var Versioned|DataObject $record */
|
|
|
|
$record = $this->record;
|
2017-01-25 21:59:25 +01:00
|
|
|
return (
|
2018-02-19 23:03:23 +01:00
|
|
|
$record->hasExtension(Versioned::class)
|
2019-10-30 10:02:18 +01:00
|
|
|
&& $this->showLiveLink()
|
2018-02-19 23:03:23 +01:00
|
|
|
&& $record->hasStages()
|
2017-01-25 21:59:25 +01:00
|
|
|
&& $this->getLivePage()
|
|
|
|
);
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2019-10-30 10:02:18 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-10-29 18:43:17 +01:00
|
|
|
public function showLiveLink()
|
|
|
|
{
|
2019-10-30 10:02:18 +01:00
|
|
|
return (bool)Config::inst()->get(get_class($this->record), 'show_live_link');
|
2019-10-29 18:43:17 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function isActive()
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(!Versioned::get_stage() || Versioned::get_stage() == 'Live')
|
|
|
|
&& !$this->isArchived()
|
|
|
|
);
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
protected function getLivePage()
|
|
|
|
{
|
|
|
|
$baseClass = $this->record->baseClass();
|
|
|
|
return Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
}
|