mirror of
https://github.com/jonom/silverstripe-betternavigator.git
synced 2024-10-22 14:05:51 +02:00
parent
7c78a7e2ed
commit
a050d926de
@ -23,52 +23,56 @@ class BetterNavigator extends DataExtension {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function BetterNavigator() {
|
public function BetterNavigator() {
|
||||||
|
// Make sure this is a page
|
||||||
|
if (!($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree && $this->owner->dataRecord->ID > 0)) return false;
|
||||||
|
|
||||||
|
// Only show navigator to appropriate users
|
||||||
$isDev = Director::isDev();
|
$isDev = Director::isDev();
|
||||||
|
$canViewDraft = (Permission::check('VIEW_DRAFT_CONTENT') || Permission::check('CMS_ACCESS_CMSMain'));
|
||||||
if($isDev || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
|
if($isDev || $canViewDraft) {
|
||||||
if($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree) {
|
// Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
||||||
|
$nav = array();
|
||||||
//Get SilverStripeNavigator links & stage info (CMS/Stage/Live/Archive)
|
$viewing = '';
|
||||||
$nav = array();
|
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
||||||
$viewing = '';
|
$items = $navigator->getItems();
|
||||||
$navigator = new SilverStripeNavigator($this->owner->dataRecord);
|
foreach($items as $item) {
|
||||||
$items = $navigator->getItems();
|
$name = $item->getName();
|
||||||
foreach($items as $item) {
|
$active = $item->isActive();
|
||||||
$name = $item->getName();
|
$nav[$name] = array(
|
||||||
$active = $item->isActive();
|
'Link' => $item->getLink(),
|
||||||
$nav[$name] = array(
|
'Active' => $active
|
||||||
'Link' => $item->getLink(),
|
);
|
||||||
'Active' => $active
|
if ($active) {
|
||||||
);
|
if ($name == 'LiveLink') $viewing = 'Live';
|
||||||
if ($active) {
|
if ($name == 'StageLink') $viewing = 'Draft';
|
||||||
if ($name == 'LiveLink') $viewing = 'Live';
|
if ($name == 'ArchiveLink') $viewing = 'Archived';
|
||||||
if ($name == 'StageLink') $viewing = 'Draft';
|
|
||||||
if ($name == 'ArchiveLink') $viewing = 'Archived';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Is the logged in member nominated as a developer?
|
|
||||||
$member = Member::currentUser();
|
|
||||||
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
|
||||||
$isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
|
|
||||||
|
|
||||||
//Add other data for template
|
|
||||||
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
|
||||||
$bNData = array_merge($nav, array(
|
|
||||||
'Member' => $member,
|
|
||||||
'Stage' => Versioned::current_stage(),
|
|
||||||
'Viewing' => $viewing, // What we're viewing doesn't necessarily align with the active Stage
|
|
||||||
'LoginLink' => Config::inst()->get('Security', 'login_url') . $backURL,
|
|
||||||
'LogoutLink' => 'Security/logout' . $backURL,
|
|
||||||
'Mode' => Director::get_environment_type(),
|
|
||||||
'IsDeveloper' => $isDeveloper
|
|
||||||
));
|
|
||||||
|
|
||||||
//Merge with page data, send to template and render
|
|
||||||
$bNData = new ArrayData($bNData);
|
|
||||||
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
|
||||||
return $page->renderWith('BetterNavigator');
|
|
||||||
}
|
}
|
||||||
|
// Only show edit link if user has permission to edit this page
|
||||||
|
$editLink = (($this->owner->dataRecord->canEdit() && Permission::check('CMS_ACCESS_CMSMain')) || $isDev) ? $nav['CMSLink']['Link'] : false;
|
||||||
|
|
||||||
|
// Is the logged in member nominated as a developer?
|
||||||
|
$member = Member::currentUser();
|
||||||
|
$devs = Config::inst()->get('BetterNavigator', 'developers');
|
||||||
|
$isDeveloper = $member && is_array($devs) ? in_array($member->Email, $devs) : false;
|
||||||
|
|
||||||
|
// Add other data for template
|
||||||
|
$backURL = '?BackURL=' . urlencode($this->owner->Link());
|
||||||
|
$bNData = array_merge($nav, array(
|
||||||
|
'Member' => $member,
|
||||||
|
'Stage' => Versioned::current_stage(),
|
||||||
|
'Viewing' => $viewing, // What we're viewing doesn't necessarily align with the active Stage
|
||||||
|
'LoginLink' => Config::inst()->get('Security', 'login_url') . $backURL,
|
||||||
|
'LogoutLink' => 'Security/logout' . $backURL,
|
||||||
|
'EditLink' => $editLink,
|
||||||
|
'Mode' => Director::get_environment_type(),
|
||||||
|
'IsDeveloper' => $isDeveloper
|
||||||
|
));
|
||||||
|
|
||||||
|
// Merge with page data, send to template and render
|
||||||
|
$bNData = new ArrayData($bNData);
|
||||||
|
$page = $this->owner->customise(array('BetterNavigator' => $bNData));
|
||||||
|
return $page->renderWith('BetterNavigator');
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,93 +1,90 @@
|
|||||||
<% if $ID > 0 %><%-- Only show on 'real' pages --%>
|
<% require javascript("betternavigator/javascript/betternavigator.js") %>
|
||||||
|
<% require css("betternavigator/css/betternavigator.css") %>
|
||||||
|
|
||||||
<% require javascript("betternavigator/javascript/betternavigator.js") %>
|
<div id="BetterNavigator" class="collapsed">
|
||||||
<% require css("betternavigator/css/betternavigator.css") %>
|
|
||||||
|
|
||||||
<div id="BetterNavigator" class="collapsed">
|
<% with $BetterNavigator %>
|
||||||
|
<div id="BetterNavigatorStatus" class="$Viewing">
|
||||||
|
<span class="bn-icon-cog"></span>
|
||||||
|
$Viewing
|
||||||
|
<span class="bn-icon-close"></span>
|
||||||
|
</div>
|
||||||
|
<% end_with %>
|
||||||
|
|
||||||
<% with $BetterNavigator %>
|
<div id="BetterNavigatorContent">
|
||||||
<div id="BetterNavigatorStatus" class="$Viewing">
|
|
||||||
<span class="bn-icon-cog"></span>
|
|
||||||
$Viewing
|
|
||||||
<span class="bn-icon-close"></span>
|
|
||||||
</div>
|
|
||||||
<% end_with %>
|
|
||||||
|
|
||||||
<div id="BetterNavigatorContent">
|
<div class="bn-links">
|
||||||
|
|
||||||
<div class="bn-links">
|
<% with $BetterNavigator %>
|
||||||
|
<% if $ArchiveLink.Active %>
|
||||||
<% with $BetterNavigator %>
|
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span>Restore</a><% end_if %>
|
||||||
<% if $ArchiveLink.Active %>
|
<% else %>
|
||||||
<a href="$CMSLink.Link" target="_blank"><span class="bn-icon-edit"></span>Restore</a>
|
<% if not $LiveLink.Active %>
|
||||||
<% else %>
|
<% if $LiveLink.Link %>
|
||||||
<% if not $LiveLink.Active %>
|
<a href="$LiveLink.Link"><span class="bn-icon-view"></span>View live</a>
|
||||||
<% if $LiveLink.Link %>
|
<% else %>
|
||||||
<a href="$LiveLink.Link"><span class="bn-icon-view"></span>View live</a>
|
<span class="bn-disabled"><span class="bn-icon-view"></span>Not yet published</span>
|
||||||
<% else %>
|
|
||||||
<span class="bn-disabled"><span class="bn-icon-view"></span>Not yet published</span>
|
|
||||||
<% end_if %>
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
<% if not $StageLink.Active %>
|
<% end_if %>
|
||||||
<% if $StageLink.Link %>
|
<% if not $StageLink.Active %>
|
||||||
<a href="$StageLink.Link"><span class="bn-icon-view"></span>View draft</a>
|
<% if $StageLink.Link %>
|
||||||
<% else %>
|
<a href="$StageLink.Link"><span class="bn-icon-view"></span>View draft</a>
|
||||||
<span class="bn-disabled"><span class="bn-icon-view"></span>Deleted from draft site</span>
|
<% else %>
|
||||||
<% end_if %>
|
<span class="bn-disabled"><span class="bn-icon-view"></span>Deleted from draft site</span>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
<a href="$CMSLink.Link" target="_blank"><span class="bn-icon-edit"></span>Edit in CMS</a>
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
<% if $EditLink %><a href="$EditLink" target="_blank"><span class="bn-icon-edit"></span>Edit in CMS</a><% end_if %>
|
||||||
|
<% end_if %>
|
||||||
|
|
||||||
<% if $Member %>
|
<% if $Member %>
|
||||||
<a href="$LogoutLink"><span class="bn-icon-user"></span>Log out<% if $Member.FirstName %><span class="light"> ($Member.FirstName)</span><% end_if %></a>
|
<a href="$LogoutLink"><span class="bn-icon-user"></span>Log out<% if $Member.FirstName %><span class="light"> ($Member.FirstName)</span><% end_if %></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
<a href="$LoginLink"><span class="bn-icon-user"></span>Log in</a>
|
<a href="$LoginLink"><span class="bn-icon-user"></span>Log in</a>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
<% end_with %>
|
<% end_with %>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% include BetterNavigatorExtraContent %>
|
|
||||||
|
|
||||||
<% if $BetterNavigator.Mode=='dev' || $BetterNavigator.IsDeveloper %>
|
|
||||||
|
|
||||||
<div class="bn-heading">Developer tools</div>
|
|
||||||
|
|
||||||
<div class="bn-links">
|
|
||||||
|
|
||||||
<% if $BetterNavigator.Mode='dev' %>
|
|
||||||
<span class="bn-disabled" title="Log out to end Dev Mode"><span class="bn-icon-tick"></span>Dev mode on</span>
|
|
||||||
<% else %>
|
|
||||||
<a href="$Link?isDev=1"><span class="bn-icon-devmode"></span>Dev mode</a>
|
|
||||||
<% end_if %>
|
|
||||||
|
|
||||||
<a href="$Link?flush=1" title="Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)"><span class="bn-icon-flush"></span>Flush caches</a>
|
|
||||||
<a href="dev/build/?flush=1" target="_blank" title="Build database and flush caches (excludes template caches pre SS-3.1.7)"><span class="bn-icon-db"></span>Build database</a>
|
|
||||||
<a href="dev" target="_blank"><span class="bn-icon-tools"></span>Dev menu</a>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% include BetterNavigatorExtraDevTools %>
|
|
||||||
|
|
||||||
<div class="bn-heading">Debugging</div>
|
|
||||||
|
|
||||||
<div class="bn-links">
|
|
||||||
|
|
||||||
<a href="$Link?showtemplate=1"><span class="bn-icon-info"></span>Show template</a>
|
|
||||||
<a href="$Link?debug=1&isDev=1"><span class="bn-icon-info"></span>Debug page</a>
|
|
||||||
<a href="$Link?debugmethods=1"><span class="bn-icon-info"></span>Debug methods</a>
|
|
||||||
<a href="$Link?debug_request=1&isDev=1"><span class="bn-icon-info"></span>Debug request</a>
|
|
||||||
<a href="$Link?debugfailover=1&isDev=1"><span class="bn-icon-info"></span>Debug failover</a>
|
|
||||||
<a href="$Link?showqueries=1&isDev=1"><span class="bn-icon-info"></span>Show queries</a>
|
|
||||||
<a href="$Link?previewwrite=1&isDev=1"><span class="bn-icon-info"></span>Preview write</a>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% include BetterNavigatorExtraDebugging %>
|
|
||||||
|
|
||||||
<% end_if %>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% include BetterNavigatorExtraContent %>
|
||||||
|
|
||||||
|
<% if $BetterNavigator.Mode=='dev' || $BetterNavigator.IsDeveloper %>
|
||||||
|
|
||||||
|
<div class="bn-heading">Developer tools</div>
|
||||||
|
|
||||||
|
<div class="bn-links">
|
||||||
|
|
||||||
|
<% if $BetterNavigator.Mode='dev' %>
|
||||||
|
<span class="bn-disabled" title="Log out to end Dev Mode"><span class="bn-icon-tick"></span>Dev mode on</span>
|
||||||
|
<% else %>
|
||||||
|
<a href="$Link?isDev=1"><span class="bn-icon-devmode"></span>Dev mode</a>
|
||||||
|
<% end_if %>
|
||||||
|
|
||||||
|
<a href="$Link?flush=1" title="Flush templates and manifest, and regenerate images for this page (behaviour varies by Framework version)"><span class="bn-icon-flush"></span>Flush caches</a>
|
||||||
|
<a href="dev/build/?flush=1" target="_blank" title="Build database and flush caches (excludes template caches pre SS-3.1.7)"><span class="bn-icon-db"></span>Build database</a>
|
||||||
|
<a href="dev" target="_blank"><span class="bn-icon-tools"></span>Dev menu</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% include BetterNavigatorExtraDevTools %>
|
||||||
|
|
||||||
|
<div class="bn-heading">Debugging</div>
|
||||||
|
|
||||||
|
<div class="bn-links">
|
||||||
|
|
||||||
|
<a href="$Link?showtemplate=1"><span class="bn-icon-info"></span>Show template</a>
|
||||||
|
<a href="$Link?debug=1&isDev=1"><span class="bn-icon-info"></span>Debug page</a>
|
||||||
|
<a href="$Link?debugmethods=1"><span class="bn-icon-info"></span>Debug methods</a>
|
||||||
|
<a href="$Link?debug_request=1&isDev=1"><span class="bn-icon-info"></span>Debug request</a>
|
||||||
|
<a href="$Link?debugfailover=1&isDev=1"><span class="bn-icon-info"></span>Debug failover</a>
|
||||||
|
<a href="$Link?showqueries=1&isDev=1"><span class="bn-icon-info"></span>Show queries</a>
|
||||||
|
<a href="$Link?previewwrite=1&isDev=1"><span class="bn-icon-info"></span>Preview write</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% include BetterNavigatorExtraDebugging %>
|
||||||
|
|
||||||
|
<% end_if %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<% end_if %>
|
|
||||||
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user