2011-03-22 10:26:53 +01:00
|
|
|
<?php
|
2016-03-22 22:00:16 +01:00
|
|
|
|
2016-07-22 01:32:32 +02:00
|
|
|
namespace SilverStripe\CMS\Controllers;
|
|
|
|
|
2022-08-06 09:07:24 +02:00
|
|
|
use SilverStripe\Admin\Navigator\SilverStripeNavigator;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\Director;
|
2016-09-09 01:26:24 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Control\HTTPResponse;
|
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2019-08-22 03:33:30 +02:00
|
|
|
use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2017-06-23 00:54:50 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2017-07-20 23:56:41 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleManifest;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\i18n\i18n;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-10 06:08:39 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
|
|
|
use SilverStripe\ORM\FieldType\DBVarchar;
|
2016-06-16 06:57:19 +02:00
|
|
|
use SilverStripe\ORM\SS_List;
|
2017-06-23 00:54:50 +02:00
|
|
|
use SilverStripe\Security\MemberAuthenticator\MemberAuthenticator;
|
2016-06-23 01:51:20 +02:00
|
|
|
use SilverStripe\Security\Permission;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Security\Security;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
2017-06-08 08:02:18 +02:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
2019-01-13 21:17:06 +01:00
|
|
|
use SilverStripe\View\Parsers\URLSegmentFilter;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
use SilverStripe\View\SSViewer;
|
2016-03-22 22:00:16 +01:00
|
|
|
|
2011-03-22 10:26:53 +01:00
|
|
|
/**
|
|
|
|
* The most common kind of controller; effectively a controller linked to a {@link DataObject}.
|
|
|
|
*
|
|
|
|
* ContentControllers are most useful in the content-focused areas of a site. This is generally
|
|
|
|
* the bulk of a site; however, they may be less appropriate in, for example, the user management
|
|
|
|
* section of an application.
|
|
|
|
*
|
|
|
|
* On its own, content controller does very little. Its constructor is passed a {@link DataObject}
|
|
|
|
* which is stored in $this->dataRecord. Any unrecognised method calls, for example, Title()
|
|
|
|
* and Content(), will be passed along to the data record,
|
|
|
|
*
|
|
|
|
* Subclasses of ContentController are generally instantiated by ModelAsController; this will create
|
|
|
|
* a controller based on the URLSegment action variable, by looking in the SiteTree table.
|
2016-03-08 21:50:55 +01:00
|
|
|
*
|
2011-03-22 10:26:53 +01:00
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class ContentController extends Controller
|
|
|
|
{
|
2018-01-12 02:39:27 +01:00
|
|
|
/**
|
|
|
|
* @var SiteTree
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
protected $dataRecord;
|
|
|
|
|
2018-01-12 02:39:27 +01:00
|
|
|
private static $extensions = [
|
|
|
|
OldPageRedirector::class,
|
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-01-12 02:39:27 +01:00
|
|
|
private static $allowed_actions = [
|
2017-01-25 21:59:25 +01:00
|
|
|
'successfullyinstalled',
|
|
|
|
'deleteinstallfiles', // secured through custom code
|
2018-01-12 02:39:27 +01:00
|
|
|
'LoginForm',
|
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
private static $casting = [
|
2018-05-01 13:59:53 +02:00
|
|
|
'SilverStripeNavigator' => 'HTMLFragment',
|
2018-05-02 12:54:59 +02:00
|
|
|
];
|
2018-05-01 13:59:53 +02:00
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
/**
|
|
|
|
* The ContentController will take the URLSegment parameter from the URL and use that to look
|
|
|
|
* up a SiteTree record.
|
|
|
|
*
|
|
|
|
* @param SiteTree $dataRecord
|
|
|
|
*/
|
|
|
|
public function __construct($dataRecord = null)
|
|
|
|
{
|
|
|
|
if (!$dataRecord) {
|
|
|
|
$dataRecord = new SiteTree();
|
|
|
|
if ($this->hasMethod("Title")) {
|
|
|
|
$dataRecord->Title = $this->Title();
|
|
|
|
}
|
|
|
|
$dataRecord->URLSegment = static::class;
|
|
|
|
$dataRecord->ID = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dataRecord = $dataRecord;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->setFailover($this->dataRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the link to this controller, but force the expanded link to be returned so that form methods and
|
|
|
|
* similar will function properly.
|
|
|
|
*
|
|
|
|
* @param string|null $action Action to link to.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function Link($action = null)
|
|
|
|
{
|
|
|
|
return $this->data()->Link(($action ? $action : true));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------//
|
|
|
|
// These flexible data methods remove the need for custom code to do simple stuff
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the children of a given page. The parent reference can either be a page link or an ID.
|
|
|
|
*
|
|
|
|
* @param string|int $parentRef
|
|
|
|
* @return SS_List
|
|
|
|
*/
|
|
|
|
public function ChildrenOf($parentRef)
|
|
|
|
{
|
|
|
|
$parent = SiteTree::get_by_link($parentRef);
|
|
|
|
|
|
|
|
if (!$parent && is_numeric($parentRef)) {
|
2017-09-20 03:51:07 +02:00
|
|
|
$parent = DataObject::get_by_id(SiteTree::class, $parentRef);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($parent) {
|
|
|
|
return $parent->Children();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $link
|
|
|
|
* @return SiteTree
|
|
|
|
*/
|
|
|
|
public function Page($link)
|
|
|
|
{
|
|
|
|
return SiteTree::get_by_link($link);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
2019-08-22 03:33:30 +02:00
|
|
|
// In the CMS Preview or draft contexts, we never want to cache page output.
|
|
|
|
if ($this->getRequest()->getVar('CMSPreview') === '1'
|
|
|
|
|| $this->getRequest()->getVar('stage') === Versioned::DRAFT
|
|
|
|
) {
|
|
|
|
HTTPCacheControlMiddleware::singleton()->disableCache(true);
|
|
|
|
}
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// If we've accessed the homepage as /home/, then we should redirect to /.
|
|
|
|
if ($this->dataRecord instanceof SiteTree
|
|
|
|
&& RootURLController::should_be_on_root($this->dataRecord)
|
2018-05-02 12:54:59 +02:00
|
|
|
&& (!isset($this->urlParams['Action']) || !$this->urlParams['Action'])
|
2017-01-25 21:59:25 +01:00
|
|
|
&& !$_POST && !$_FILES && !$this->redirectedTo()
|
|
|
|
) {
|
|
|
|
$getVars = $_GET;
|
|
|
|
unset($getVars['url']);
|
|
|
|
if ($getVars) {
|
2022-04-13 07:07:59 +02:00
|
|
|
$url = "?" . http_build_query($getVars ?? []);
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
$url = "";
|
|
|
|
}
|
|
|
|
$this->redirect($url, 301);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->dataRecord) {
|
|
|
|
$this->dataRecord->extend('contentcontrollerInit', $this);
|
|
|
|
} else {
|
|
|
|
SiteTree::singleton()->extend('contentcontrollerInit', $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->redirectedTo()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check page permissions
|
|
|
|
if ($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->canView()) {
|
|
|
|
Security::permissionFailure($this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to
|
|
|
|
* fall over to a child controller in order to provide functionality for nested URLs.
|
|
|
|
*
|
|
|
|
* @throws HTTPResponse_Exception
|
|
|
|
*/
|
2022-10-18 07:21:09 +02:00
|
|
|
public function handleRequest(HTTPRequest $request): HTTPResponse
|
2017-01-25 21:59:25 +01:00
|
|
|
{
|
|
|
|
/** @var SiteTree $child */
|
2018-05-02 12:54:59 +02:00
|
|
|
$child = null;
|
2017-01-25 21:59:25 +01:00
|
|
|
$action = $request->param('Action');
|
|
|
|
|
|
|
|
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
|
|
|
|
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
|
|
|
|
// nested URL.
|
|
|
|
if ($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) {
|
2019-01-13 21:17:06 +01:00
|
|
|
$filter = URLSegmentFilter::create();
|
|
|
|
|
2017-01-25 21:59:25 +01:00
|
|
|
// look for a page with this URLSegment
|
2018-05-02 12:54:59 +02:00
|
|
|
$child = SiteTree::get()->filter([
|
2017-01-25 21:59:25 +01:00
|
|
|
'ParentID' => $this->ID,
|
2019-01-13 21:17:06 +01:00
|
|
|
// url encode unless it's multibyte (already pre-encoded in the database)
|
|
|
|
'URLSegment' => $filter->getAllowMultibyte() ? $action : rawurlencode($action),
|
2018-05-02 12:54:59 +02:00
|
|
|
])->first();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// we found a page with this URLSegment.
|
|
|
|
if ($child) {
|
|
|
|
$request->shiftAllParams();
|
|
|
|
$request->shift();
|
|
|
|
|
2017-06-08 08:02:18 +02:00
|
|
|
$response = ModelAsController::controller_for($child)->handleRequest($request);
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
Director::set_current_page($this->data());
|
|
|
|
|
|
|
|
try {
|
2017-06-08 08:02:18 +02:00
|
|
|
$response = parent::handleRequest($request);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
Director::set_current_page(null);
|
|
|
|
} catch (HTTPResponse_Exception $e) {
|
|
|
|
$this->popCurrent();
|
|
|
|
|
|
|
|
Director::set_current_page(null);
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the project name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function project()
|
|
|
|
{
|
2017-07-21 00:10:53 +02:00
|
|
|
return ModuleManifest::config()->get('project');
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the associated database record
|
|
|
|
*/
|
|
|
|
public function data()
|
|
|
|
{
|
|
|
|
return $this->dataRecord;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a fixed navigation menu of the given level.
|
|
|
|
* @param int $level Menu level to return.
|
|
|
|
* @return ArrayList
|
|
|
|
*/
|
|
|
|
public function getMenu($level = 1)
|
|
|
|
{
|
|
|
|
if ($level == 1) {
|
2018-05-02 12:54:59 +02:00
|
|
|
$result = SiteTree::get()->filter([
|
2017-01-25 21:59:25 +01:00
|
|
|
"ShowInMenus" => 1,
|
2018-05-02 12:54:59 +02:00
|
|
|
"ParentID" => 0,
|
|
|
|
]);
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
$parent = $this->data();
|
2018-05-02 12:54:59 +02:00
|
|
|
$stack = [$parent];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
if ($parent) {
|
|
|
|
while (($parent = $parent->Parent()) && $parent->exists()) {
|
|
|
|
array_unshift($stack, $parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
if (isset($stack[$level - 2])) {
|
|
|
|
$result = $stack[$level - 2]->Children();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
$visible = [];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
// Remove all entries the can not be viewed by the current user
|
|
|
|
// We might need to create a show in menu permission
|
|
|
|
if (isset($result)) {
|
|
|
|
foreach ($result as $page) {
|
2018-01-12 02:39:27 +01:00
|
|
|
/** @var SiteTree $page */
|
2017-01-25 21:59:25 +01:00
|
|
|
if ($page->canView()) {
|
|
|
|
$visible[] = $page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ArrayList($visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Menu($level)
|
|
|
|
{
|
|
|
|
return $this->getMenu($level);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default log-in form.
|
|
|
|
*
|
2017-06-23 00:54:50 +02:00
|
|
|
* @return \SilverStripe\Security\MemberAuthenticator\MemberLoginForm
|
2017-01-25 21:59:25 +01:00
|
|
|
*/
|
|
|
|
public function LoginForm()
|
|
|
|
{
|
2017-06-23 00:54:50 +02:00
|
|
|
return Injector::inst()->get(MemberAuthenticator::class)->getLoginHandler($this->Link())->loginForm();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function SilverStripeNavigator()
|
|
|
|
{
|
2017-05-21 05:15:00 +02:00
|
|
|
$member = Security::getCurrentUser();
|
2017-01-25 21:59:25 +01:00
|
|
|
$items = '';
|
|
|
|
$message = '';
|
|
|
|
|
|
|
|
if (Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
|
|
|
|
if ($this->dataRecord) {
|
2017-06-28 00:17:09 +02:00
|
|
|
Requirements::css('silverstripe/cms: client/dist/styles/SilverStripeNavigator.css');
|
|
|
|
Requirements::javascript('silverstripe/cms: client/dist/js/SilverStripeNavigator.js');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord);
|
|
|
|
$items = $return['items'];
|
|
|
|
$message = $return['message'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($member) {
|
|
|
|
$firstname = Convert::raw2xml($member->FirstName);
|
|
|
|
$surname = Convert::raw2xml($member->Surname);
|
2018-05-28 08:20:46 +02:00
|
|
|
$logInMessage = _t(__CLASS__ . '.LOGGEDINAS', 'Logged in as') . " {$firstname} {$surname} - <a href=\"Security/logout\">" . _t(__CLASS__ . '.LOGOUT', 'Log out') . "</a>";
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
$logInMessage = sprintf(
|
|
|
|
'%s - <a href="%s">%s</a>',
|
2018-01-12 02:39:27 +01:00
|
|
|
_t(__CLASS__ . '.NOTLOGGEDIN', 'Not logged in'),
|
2017-01-25 21:59:25 +01:00
|
|
|
Security::config()->login_url,
|
2018-05-28 08:20:46 +02:00
|
|
|
_t(__CLASS__ . '.LOGIN', 'Login') . "</a>"
|
2017-01-25 21:59:25 +01:00
|
|
|
);
|
|
|
|
}
|
2018-01-12 02:39:27 +01:00
|
|
|
$viewPageIn = _t(__CLASS__ . '.VIEWPAGEIN', 'View Page in:');
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-01 14:00:11 +02:00
|
|
|
return <<<HTML
|
2011-03-22 10:26:53 +01:00
|
|
|
<div id="SilverStripeNavigator">
|
|
|
|
<div class="holder">
|
|
|
|
<div id="logInStatus">
|
|
|
|
$logInMessage
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="switchView" class="bottomTabs">
|
2016-03-08 21:50:55 +01:00
|
|
|
$viewPageIn
|
2011-03-22 10:26:53 +01:00
|
|
|
$items
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
$message
|
|
|
|
HTML;
|
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
// On live sites we should still see the archived message
|
2017-01-25 21:59:25 +01:00
|
|
|
} else {
|
|
|
|
if ($date = Versioned::current_archived_date()) {
|
2017-06-28 00:17:09 +02:00
|
|
|
Requirements::css('silverstripe/cms: client/dist/styles/SilverStripeNavigator.css');
|
2017-01-25 21:59:25 +01:00
|
|
|
/** @var DBDatetime $dateObj */
|
|
|
|
$dateObj = DBField::create_field('Datetime', $date);
|
|
|
|
// $dateObj->setVal($date);
|
2018-05-01 14:00:11 +02:00
|
|
|
return "<div id=\"SilverStripeNavigatorMessage\">" .
|
2018-01-12 02:39:27 +01:00
|
|
|
_t(__CLASS__ . '.ARCHIVEDSITEFROM', 'Archived site from') .
|
2018-05-01 14:00:11 +02:00
|
|
|
"<br>" . $dateObj->Nice() . "</div>";
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function SiteConfig()
|
|
|
|
{
|
|
|
|
if (method_exists($this->dataRecord, 'getSiteConfig')) {
|
|
|
|
return $this->dataRecord->getSiteConfig();
|
|
|
|
} else {
|
|
|
|
return SiteConfig::current_site_config();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an RFC1766 compliant locale string, e.g. 'fr-CA'.
|
|
|
|
*
|
|
|
|
* Suitable for insertion into lang= and xml:lang=
|
|
|
|
* attributes in HTML or XHTML output.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function ContentLocale()
|
|
|
|
{
|
2023-01-18 02:07:39 +01:00
|
|
|
$locale = i18n::get_locale();
|
2017-01-25 21:59:25 +01:00
|
|
|
return i18n::convert_rfc1766($locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an SSViewer object to render the template for the current page.
|
|
|
|
*
|
|
|
|
* @param $action string
|
|
|
|
*
|
|
|
|
* @return SSViewer
|
|
|
|
*/
|
|
|
|
public function getViewer($action)
|
|
|
|
{
|
|
|
|
// Manually set templates should be dealt with by Controller::getViewer()
|
2018-08-17 14:51:36 +02:00
|
|
|
if (!empty($this->templates[$action])
|
|
|
|
|| !empty($this->templates['index'])
|
2017-01-25 21:59:25 +01:00
|
|
|
|| $this->template
|
|
|
|
) {
|
|
|
|
return parent::getViewer($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare action for template search
|
2018-08-17 14:38:24 +02:00
|
|
|
$action = $action === 'index' ? '' : '_' . $action;
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-12-05 23:59:30 +01:00
|
|
|
$templatesFound = [];
|
|
|
|
// Find templates for the record + action together - e.g. Page_action.ss
|
|
|
|
if ($this->dataRecord instanceof SiteTree) {
|
|
|
|
$templatesFound[] = $this->dataRecord->getViewerTemplates($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find templates for the controller + action together - e.g. PageController_action.ss
|
|
|
|
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action, Controller::class);
|
|
|
|
|
|
|
|
// Find templates for the record without an action - e.g. Page.ss
|
|
|
|
if ($this->dataRecord instanceof SiteTree) {
|
|
|
|
$templatesFound[] = $this->dataRecord->getViewerTemplates();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the templates for the controller without an action - e.g. PageController.ss
|
|
|
|
$templatesFound[] = SSViewer::get_templates_by_class(static::class, "", Controller::class);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2017-12-05 23:59:30 +01:00
|
|
|
$templates = array_merge(...$templatesFound);
|
2017-07-13 05:45:35 +02:00
|
|
|
return SSViewer::create($templates);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This action is called by the installation system
|
|
|
|
*/
|
|
|
|
public function successfullyinstalled()
|
|
|
|
{
|
|
|
|
// Return 410 Gone if this site is not actually a fresh installation
|
2018-01-12 02:39:27 +01:00
|
|
|
if (!file_exists(PUBLIC_PATH . '/install.php')) {
|
2017-01-25 21:59:25 +01:00
|
|
|
$this->httpError(410);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
|
|
|
|
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
|
2022-04-13 07:07:59 +02:00
|
|
|
@file_get_contents($url ?? '');
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
global $project;
|
2018-05-02 12:54:59 +02:00
|
|
|
$data = new ArrayData([
|
2017-01-25 21:59:25 +01:00
|
|
|
'Project' => Convert::raw2xml($project),
|
2017-06-08 08:02:18 +02:00
|
|
|
'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')),
|
|
|
|
'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')),
|
2018-05-02 12:54:59 +02:00
|
|
|
]);
|
2017-01-25 21:59:25 +01:00
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
return [
|
2018-01-12 02:39:27 +01:00
|
|
|
"Title" => _t(__CLASS__ . ".INSTALL_SUCCESS", "Installation Successful!"),
|
2017-01-25 21:59:25 +01:00
|
|
|
"Content" => $data->renderWith([
|
|
|
|
'type' => 'Includes',
|
2018-05-02 12:54:59 +02:00
|
|
|
'Install_successfullyinstalled',
|
2017-01-25 21:59:25 +01:00
|
|
|
]),
|
2018-05-02 12:54:59 +02:00
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteinstallfiles()
|
|
|
|
{
|
|
|
|
if (!Permission::check("ADMIN")) {
|
|
|
|
return Security::permissionFailure($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = new DBVarchar("Title");
|
|
|
|
$content = new DBHTMLText('Content');
|
|
|
|
|
2018-05-24 00:08:43 +02:00
|
|
|
// As of SS4, index.php is required and should never be deleted.
|
2020-04-19 06:18:01 +02:00
|
|
|
$installfiles = [
|
2017-01-25 21:59:25 +01:00
|
|
|
'install.php',
|
2018-05-24 00:08:43 +02:00
|
|
|
'install-frameworkmissing.html',
|
|
|
|
'index.html'
|
2020-04-19 06:18:01 +02:00
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$unsuccessful = new ArrayList();
|
|
|
|
foreach ($installfiles as $installfile) {
|
2018-05-24 00:08:43 +02:00
|
|
|
$installfilepath = PUBLIC_PATH . '/' . $installfile;
|
2022-04-13 07:07:59 +02:00
|
|
|
if (file_exists($installfilepath ?? '')) {
|
|
|
|
@unlink($installfilepath ?? '');
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
2022-04-13 07:07:59 +02:00
|
|
|
if (file_exists($installfilepath ?? '')) {
|
2020-04-19 06:18:01 +02:00
|
|
|
$unsuccessful->push(new ArrayData(['File' => $installfile]));
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
$data = new ArrayData([
|
2017-06-08 08:02:18 +02:00
|
|
|
'Username' => Convert::raw2xml($this->getRequest()->getSession()->get('username')),
|
|
|
|
'Password' => Convert::raw2xml($this->getRequest()->getSession()->get('password')),
|
2018-05-02 12:54:59 +02:00
|
|
|
'UnsuccessfulFiles' => $unsuccessful,
|
|
|
|
]);
|
2017-01-25 21:59:25 +01:00
|
|
|
$content->setValue($data->renderWith([
|
|
|
|
'type' => 'Includes',
|
2018-05-02 12:54:59 +02:00
|
|
|
'Install_deleteinstallfiles',
|
2017-01-25 21:59:25 +01:00
|
|
|
]));
|
|
|
|
|
2018-05-02 12:54:59 +02:00
|
|
|
return [
|
2017-01-25 21:59:25 +01:00
|
|
|
"Title" => $title,
|
|
|
|
"Content" => $content,
|
2018-05-02 12:54:59 +02:00
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2012-03-27 06:05:11 +02:00
|
|
|
}
|