mirror of
https://github.com/jonom/silverstripe-betternavigator.git
synced 2024-10-22 14:05:51 +02:00
Converted to PSR-2
This commit is contained in:
parent
4f92851547
commit
f2831766e6
@ -1,66 +1,68 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class BetterNavigator extends DataExtension {
|
class BetterNavigator extends DataExtension
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nominate developers who can access developer tools on live site
|
* Nominate developers who can access developer tools on live site
|
||||||
* Example YAML:
|
* Example YAML:
|
||||||
*
|
*
|
||||||
* BetterNavigator:
|
* BetterNavigator:
|
||||||
* developers:
|
* developers:
|
||||||
* - 'dev@yoursite.com'
|
* - 'dev@yoursite.com'
|
||||||
* - 'otherdev@yoursite.com'
|
* - 'otherdev@yoursite.com'
|
||||||
*
|
*
|
||||||
* @config
|
* @config
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $developers;
|
private static $developers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a front-end utility menu with administrative functions and developer tools
|
* Provides a front-end utility menu with administrative functions and developer tools
|
||||||
* Relies on SilverStripeNavigator
|
* Relies on SilverStripeNavigator
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function BetterNavigator() {
|
public function BetterNavigator()
|
||||||
$isDev = Director::isDev();
|
{
|
||||||
|
$isDev = Director::isDev();
|
||||||
|
|
||||||
if($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
|
if ($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
|
||||||
if($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree) {
|
if ($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree) {
|
||||||
|
|
||||||
//Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
//Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
||||||
$nav = array();
|
$nav = array();
|
||||||
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
||||||
$items = $navigator->getItems();
|
$items = $navigator->getItems();
|
||||||
foreach($items as $item) {
|
foreach ($items as $item) {
|
||||||
$nav[$item->getName()] = array(
|
$nav[$item->getName()] = array(
|
||||||
'Link' => $item->getLink(),
|
'Link' => $item->getLink(),
|
||||||
'Active' => $item->isActive()
|
'Active' => $item->isActive()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Is the logged in member nominated as a developer?
|
//Is the logged in member nominated as a developer?
|
||||||
$member = Member::currentUser();
|
$member = Member::currentUser();
|
||||||
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
||||||
$isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
|
$isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
|
||||||
|
|
||||||
//Add other data for template
|
//Add other data for template
|
||||||
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
||||||
$bNData = array_merge($nav, array(
|
$bNData = array_merge($nav, array(
|
||||||
'Member' => $member,
|
'Member' => $member,
|
||||||
'Stage' => Versioned::current_stage(),
|
'Stage' => Versioned::current_stage(),
|
||||||
'LoginLink' => Config::inst()->get('Security', 'login_url') . $backURL,
|
'LoginLink' => Config::inst()->get('Security', 'login_url') . $backURL,
|
||||||
'LogoutLink' => 'Security/logout' . $backURL,
|
'LogoutLink' => 'Security/logout' . $backURL,
|
||||||
'Mode' => Director::get_environment_type(),
|
'Mode' => Director::get_environment_type(),
|
||||||
'IsDeveloper' => $isDeveloper
|
'IsDeveloper' => $isDeveloper
|
||||||
));
|
));
|
||||||
|
|
||||||
//Merge with page data, send to template and render
|
//Merge with page data, send to template and render
|
||||||
$bNData = new ArrayData($bNData);
|
$bNData = new ArrayData($bNData);
|
||||||
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
||||||
return $page->renderWith('BetterNavigator');
|
return $page->renderWith('BetterNavigator');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user