Skip to content

Commit

Permalink
formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerkrauss committed Jun 1, 2017
1 parent 55c7240 commit a4a1ab6
Show file tree
Hide file tree
Showing 22 changed files with 339 additions and 317 deletions.
10 changes: 5 additions & 5 deletions code/controller/SubsiteXHRController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function canView($member = null)
*/
public function canAccess()
{
// Allow if any cms access is available
return Permission::check(array(
'CMS_ACCESS', // Supported by 3.1.14 and up
'CMS_ACCESS_LeftAndMain'
));
// Allow if any cms access is available
return Permission::check([
'CMS_ACCESS', // Supported by 3.1.14 and up
'CMS_ACCESS_LeftAndMain'
]);
}

public function getResponseNegotiator()
Expand Down
1 change: 1 addition & 0 deletions code/extensions/CMSPageAddControllerExtension.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace SilverStripe\Subsites\Extensions;

use SilverStripe\Core\Extension;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Subsites\Model\Subsite;
Expand Down
15 changes: 8 additions & 7 deletions code/extensions/ControllerSubsites.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace SilverStripe\Subsites\Extensions;

use SilverStripe\Core\Extension;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer;
Expand All @@ -13,18 +14,18 @@ class ControllerSubsites extends Extension

public function controllerAugmentInit()
{
if ($subsite = Subsite::currentSubsite()) {
if ($theme = $subsite->Theme) {
SSViewer::set_themes([$theme, SSViewer::DEFAULT_THEME]);
}
$subsite = $this->CurrentSubsite();
if ($subsite && $theme = $subsite->Theme) {
SSViewer::set_themes([$theme, SSViewer::DEFAULT_THEME]);
}
}

/**
* @return Subsite
*/
public function CurrentSubsite()
{
if ($subsite = Subsite::currentSubsite()) {
return $subsite;
}
return Subsite::currentSubsite();
}

}
4 changes: 2 additions & 2 deletions code/extensions/ErrorPageSubsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace SilverStripe\Subsites\Extensions;

use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataObject;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Model\Subsite;

class ErrorPageSubsite extends DataExtension
Expand Down
83 changes: 42 additions & 41 deletions code/extensions/GroupSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
*/
class GroupSubsites extends DataExtension implements PermissionProvider
{
private static $db = [
'AccessAllSubsites' => 'Boolean'
];
private static $db = [
'AccessAllSubsites' => 'Boolean'
];

private static $many_many = [
'Subsites' => Subsite::class
];
private static $many_many = [
'Subsites' => Subsite::class
];

private static $defaults = [
'AccessAllSubsites' => true
];
private static $defaults = [
'AccessAllSubsites' => true
];

/**
* Migrations for GroupSubsites data.
Expand Down Expand Up @@ -68,7 +68,8 @@ public function requireDefaultRecords()
if (!DB::query('SELECT "Group"."ID" FROM "Group"
LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0
WHERE "AccessAllSubsites" = 1
OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()) {
OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()
) {
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1');
}
}
Expand All @@ -83,37 +84,37 @@ public function updateCMSFields(FieldList $fields)
$subsites = Subsite::accessible_sites(['ADMIN', 'SECURITY_SUBSITE_GROUP'], true);
$subsiteMap = $subsites->map();

// Prevent XSS injection
$subsiteMap = Convert::raw2xml($subsiteMap->toArray());

// Interface is different if you have the rights to modify subsite group values on
// all subsites
if(isset($subsiteMap[0])) {
$fields->addFieldToTab('Root.Subsites', new OptionsetField('AccessAllSubsites',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
[
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
0 => _t('GroupSubsites.ACCESSONLY', 'Only these subsites'),
]
));

unset($subsiteMap[0]);
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '',
$subsiteMap));

} else {
if (sizeof($subsiteMap) <= 1) {
$fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
reset($subsiteMap)));
} else {
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
$subsiteMap));
}
}
}
}
// Prevent XSS injection
$subsiteMap = Convert::raw2xml($subsiteMap->toArray());

// Interface is different if you have the rights to modify subsite group values on
// all subsites
if (isset($subsiteMap[0])) {
$fields->addFieldToTab('Root.Subsites', new OptionsetField('AccessAllSubsites',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
[
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
0 => _t('GroupSubsites.ACCESSONLY', 'Only these subsites'),
]
));

unset($subsiteMap[0]);
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '',
$subsiteMap));

} else {
if (sizeof($subsiteMap) <= 1) {
$fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
reset($subsiteMap)));
} else {
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
$subsiteMap));
}
}
}
}

/**
* If this group belongs to a subsite,
Expand Down
43 changes: 23 additions & 20 deletions code/extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace SilverStripe\Subsites\Extensions;


use Page;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTP;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
Expand All @@ -35,13 +34,13 @@ class SiteTreeSubsites extends DataExtension
'Subsite' => Subsite::class, // The subsite that this page belongs to
];

private static $many_many = array(
private static $many_many = [
'CrossSubsiteLinkTracking' => SiteTree::class // Stored separately, as the logic for URL rewriting is different
);
];

private static $many_many_extraFields = array(
'CrossSubsiteLinkTracking' => array('FieldName' => 'Varchar')
);
private static $many_many_extraFields = [
'CrossSubsiteLinkTracking' => ['FieldName' => 'Varchar']
];

public function isMainSite()
{
Expand Down Expand Up @@ -72,7 +71,8 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
$subsiteID = Subsite::$force_subsite;
} else {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID();
else */
$subsiteID = (int)Subsite::currentSubsiteID();
}

// The foreach is an ugly way of getting the first key :-)
Expand All @@ -99,7 +99,7 @@ public function onBeforeWrite()
public function updateCMSFields(FieldList $fields)
{
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
$subsitesMap = array();
$subsitesMap = [];
if ($subsites && $subsites->count()) {
$subsitesToMap = $subsites->exclude('ID', $this->owner->SubsiteID);
$subsitesMap = $subsitesToMap->map('ID', 'Title');
Expand All @@ -113,15 +113,16 @@ public function updateCMSFields(FieldList $fields)
'Root.Main',
ToggleCompositeField::create('SubsiteOperations',
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
array(
[
new DropdownField('CopyToSubsiteID', _t('SiteTreeSubsites.CopyToSubsite',
'Copy page to subsite'), $subsitesMap),
new CheckboxField('CopyToSubsiteWithChildren', _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
new CheckboxField('CopyToSubsiteWithChildren',
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
$copyAction = new InlineFormAction(
'copytosubsite',
_t('SiteTreeSubsites.CopyAction', 'Copy')
)
)
]
)->setHeadingLevel(4)
);

Expand All @@ -137,7 +138,7 @@ public function updateCMSFields(FieldList $fields)
$baseLink = $subsite->absoluteBaseURL();

// Add parent page if enabled
if($nested_urls_enabled && $this->owner->ParentID) {
if ($nested_urls_enabled && $this->owner->ParentID) {
$baseLink = Controller::join_links(
$baseLink,
$this->owner->Parent()->RelativeLink(true)
Expand Down Expand Up @@ -278,8 +279,8 @@ public function duplicateToSubsite($subsiteID = null, $includeChildren = false,

Subsite::changeSubsite($oldSubsite);

if($includeChildren) {
foreach($this->owner->AllChildren() as $child) {
if ($includeChildren) {
foreach ($this->owner->AllChildren() as $child) {
$child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID);
}
}
Expand All @@ -306,7 +307,7 @@ public function alternateAbsoluteLink()
// This helps deal with Link() returning an absolute URL.
$url = Director::absoluteURL($this->owner->Link());
if ($this->owner->SubsiteID) {
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
}
return $url;
}
Expand Down Expand Up @@ -344,7 +345,7 @@ public function augmentSyncLinkTracking()
{
// Set LinkTracking appropriately
$links = HTTP::getLinksIn($this->owner->Content);
$linkedPages = array();
$linkedPages = [];

if ($links) {
foreach ($links as $link) {
Expand All @@ -359,9 +360,11 @@ public function augmentSyncLinkTracking()
continue;
} // We have no idea what the domain for the main site is, so cant track links to it

$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true);
$candidatePage = DataObject::get_one(SiteTree::class, "\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false);
$candidatePage = DataObject::get_one(SiteTree::class,
"\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID,
false);
Subsite::disable_subsite_filter($origDisableSubsiteFilter);

if ($candidatePage) {
Expand Down Expand Up @@ -409,7 +412,7 @@ public function augmentValidURLSegment()
*/
public function cacheKeyComponent()
{
return 'subsite-'.Subsite::currentSubsiteID();
return 'subsite-' . Subsite::currentSubsiteID();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions code/forms/GridFieldSubsiteDetailForm_ItemRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
{

private static $allowed_actions = array(
private static $allowed_actions = [
'ItemEditForm',
);
];

/**
* Builds an item edit form. The arguments to getCMSFields() are the popupController and
Expand All @@ -26,16 +26,17 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
*/
public function ItemEditForm()
{
$form=parent::ItemEditForm();
$form = parent::ItemEditForm();

if ($this->record->ID == 0) {
$templates = Subsite::get()->sort('Title');
$templateArray = array();
$templateArray = [];
if ($templates) {
$templateArray = $templates->map('ID', 'Title');
}

$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), $templateArray);
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'),
$templateArray);
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
}
Expand Down
8 changes: 4 additions & 4 deletions code/forms/SubsitesTreeDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/
class SubsitesTreeDropdownField extends TreeDropdownField
{
private static $allowed_actions = array(
private static $allowed_actions = [
'tree'
);
];

protected $subsiteID = 0;

protected $extraClasses = array('SubsitesTreeDropdownField');
protected $extraClasses = ['SubsitesTreeDropdownField'];

public function Field($properties = array())
public function Field($properties = [])
{
$html = parent::Field($properties);

Expand Down
4 changes: 2 additions & 2 deletions code/tasks/SubsiteCopyPagesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function run($request)
// This will make sure that the new parents on the new subsite are correct, and there are no funny
// issues with having to check whether or not the new parents have been added to the site tree
// when a page, etc, is duplicated
$stack = array(array(0,0));
$stack = [[0, 0]];
while (count($stack) > 0) {
list($sourceParentID, $destParentID) = array_pop($stack);

Expand All @@ -75,7 +75,7 @@ public function run($request)
$childClone->ParentID = $destParentID;
$childClone->writeToStage('Stage');
$childClone->copyVersionToStage('Stage', 'Live');
array_push($stack, array($child->ID, $childClone->ID));
array_push($stack, [$child->ID, $childClone->ID]);

$this->log(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link()));
}
Expand Down
Loading

0 comments on commit a4a1ab6

Please sign in to comment.