2016-08-16 03:22:58 +02:00
|
|
|
<?php
|
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Model\RedirectorPage;
|
2016-09-08 09:33:32 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Core\Convert;
|
2023-03-01 01:41:01 +01:00
|
|
|
use SilverStripe\Dev\Deprecation;
|
|
|
|
use SilverStripe\ORM\CMSPreviewable;
|
2018-02-19 23:03:23 +01:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-16 03:22:58 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
2017-03-21 05:26:46 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2023-03-01 01:41:01 +01:00
|
|
|
/**
|
|
|
|
* Class will be moved from `silverstripe/cms` to `silverstripe/admin`
|
|
|
|
* @deprecated 4.13.0 Will be renamed SilverStripe\VersionedAdmin\Navigator\SilverStripeNavigatorItem_ArchiveLink
|
|
|
|
*/
|
2016-08-16 03:22:58 +02:00
|
|
|
class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
|
|
|
|
{
|
2023-03-01 01:41:01 +01:00
|
|
|
/**
|
|
|
|
* @param DataObject|CMSPreviewable $record
|
|
|
|
*/
|
|
|
|
public function __construct(CMSPreviewable $record)
|
|
|
|
{
|
|
|
|
Deprecation::withNoReplacement(function () {
|
|
|
|
Deprecation::notice(
|
|
|
|
'4.13.0',
|
|
|
|
'Will be renamed SilverStripe\VersionedAdmin\Navigator\SilverStripeNavigatorItem_ArchiveLink',
|
|
|
|
Deprecation::SCOPE_CLASS
|
|
|
|
);
|
|
|
|
});
|
|
|
|
parent::__construct($record);
|
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
/** @config */
|
|
|
|
private static $priority = 40;
|
2016-08-16 03:22:58 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
public function getHTML()
|
|
|
|
{
|
2016-09-07 11:24:30 +02:00
|
|
|
$linkClass = $this->isActive() ? 'ss-ui-button current' : 'ss-ui-button';
|
2017-04-20 03:15:29 +02:00
|
|
|
$linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITE', 'Preview version');
|
2016-09-07 11:24:30 +02:00
|
|
|
$recordLink = Convert::raw2att(Controller::join_links(
|
|
|
|
$this->record->AbsoluteLink(),
|
2022-04-13 07:07:59 +02:00
|
|
|
'?archiveDate=' . urlencode($this->record->LastEdited ?? '')
|
2016-09-07 11:24:30 +02:00
|
|
|
));
|
|
|
|
return "<a class=\"{$linkClass}\" href=\"$recordLink\" target=\"_blank\">$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()
|
|
|
|
{
|
2017-04-20 03:15:29 +02:00
|
|
|
return _t('SilverStripe\\CMS\\Controllers\\SilverStripeNavigator.ARCHIVED', 'Archived');
|
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 getMessage()
|
|
|
|
{
|
2016-09-07 11:24:30 +02:00
|
|
|
$date = Versioned::current_archived_date();
|
|
|
|
if (empty($date)) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-09-08 09:33:32 +02:00
|
|
|
/** @var DBDatetime $dateObj */
|
2016-09-07 11:24:30 +02:00
|
|
|
$dateObj = DBField::create_field('Datetime', $date);
|
2017-04-20 03:45:23 +02:00
|
|
|
$title = _t('SilverStripe\\CMS\\Controllers\\ContentController.NOTEWONTBESHOWN', 'Note: this message will not be shown to your visitors');
|
2016-09-07 11:24:30 +02:00
|
|
|
return "<div id=\"SilverStripeNavigatorMessage\" title=\"{$title}\">"
|
2017-04-20 03:15:29 +02:00
|
|
|
. _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITEFROM', 'Archived site from')
|
2016-09-07 11:24:30 +02:00
|
|
|
. "<br />" . $dateObj->Nice() . "</div>";
|
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 getLink()
|
|
|
|
{
|
2022-05-04 02:43:23 +02:00
|
|
|
$link = $this->record->PreviewLink();
|
|
|
|
return $link ? Controller::join_links($link, '?archiveDate=' . urlencode($this->record->LastEdited ?? '')) : '';
|
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)
|
|
|
|
&& $record->hasStages()
|
2017-01-25 21:59:25 +01:00
|
|
|
&& $this->isArchived()
|
|
|
|
// Don't follow redirects in preview, they break the CMS editing form
|
2018-02-19 23:03:23 +01:00
|
|
|
&& !($record instanceof RedirectorPage)
|
2022-05-04 02:43:23 +02:00
|
|
|
&& $this->getLink()
|
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 isActive()
|
|
|
|
{
|
|
|
|
return $this->isArchived();
|
|
|
|
}
|
2016-08-16 03:22:58 +02:00
|
|
|
}
|