2010-02-16 01:41:41 +01:00
< ? php
2010-02-16 03:23:44 +01:00
/**
* @ package cms
* @ subpackage content
*/
class SilverStripeNavigator {
2010-02-16 01:41:41 +01:00
2010-02-16 03:23:44 +01:00
/**
* @ param SiteTree $record
* @ return Array template data
*/
static function get_for_record ( $record ) {
$items = '' ;
$message = '' ;
$navItemClasses = ClassInfo :: subclassesFor ( 'SilverStripeNavigatorItem' );
array_shift ( $navItemClasses );
// Sort menu items according to priority
$menuPriority = array ();
$i = 0 ;
foreach ( $navItemClasses as $navItemClass ) {
if ( $navItemClass == 'SilverStripeNavigatorItem' ) continue ;
$i ++ ;
$obj = new $navItemClass ();
// This funny litle formula ensures that the first item added with the same priority will be left-most.
$priority = Object :: get_static ( $navItemClass , 'priority' );
$menuPriority [ $priority * 100 - 1 ] = $obj ;
}
ksort ( $menuPriority );
foreach ( $menuPriority as $obj ) {
$text = $obj -> getHTML ( $record );
if ( $text ) $items .= $text ;
$newMessage = $obj -> getMessage ( $record );
if ( $newMessage ) $message = $newMessage ;
}
return array (
'items' => $items ,
'message' => $message
);
}
}
2010-02-16 01:41:41 +01:00
/**
* Navigator items are links that appear in the $SilverStripeNavigator bar .
* To add an item , extends this class .
2010-02-16 03:23:44 +01:00
*
* @ package cms
* @ subpackage content
2010-02-16 01:41:41 +01:00
*/
class SilverStripeNavigatorItem extends Object {
2010-02-16 03:26:55 +01:00
function getHTML ( $page ) {}
function getMessage ( $page ) {}
2010-02-16 01:41:41 +01:00
}
2010-02-16 03:23:44 +01:00
/**
* @ package cms
* @ subpackage content
*/
2010-02-16 01:41:41 +01:00
class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem {
static $priority = 10 ;
2010-02-16 03:26:55 +01:00
function getHTML ( $page ) {
2010-02-16 01:46:30 +01:00
if ( is_a ( Controller :: curr (), 'CMSMain' )) {
return '<a class="current">CMS</a>' ;
} else {
2012-01-31 15:51:23 +01:00
$cmsLink = Convert :: raw2att ( 'admin/show/' . $page -> ID );
2010-02-16 03:26:55 +01:00
$cmsLink = " <a href= \" $cmsLink\ " class = \ " newWindow \" target= \" cms \" > " . _t ( 'ContentController.CMS' , 'CMS' ) . " </a> " ;
2010-02-16 01:41:41 +01:00
2010-02-16 01:46:30 +01:00
return $cmsLink ;
}
2010-02-16 01:41:41 +01:00
}
2010-02-16 01:48:39 +01:00
function getLink ( $page ) {
if ( is_a ( Controller :: curr (), 'CMSMain' )) {
2010-02-16 03:26:55 +01:00
return Controller :: curr () -> AbsoluteLink ( 'show' ) . $page -> ID ;
2010-02-16 01:48:39 +01:00
}
}
2010-02-16 01:41:41 +01:00
}
2010-02-16 03:23:44 +01:00
/**
* @ package cms
* @ subpackage content
*/
2010-02-16 01:41:41 +01:00
class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem {
static $priority = 20 ;
2010-02-16 03:26:55 +01:00
function getHTML ( $page ) {
2010-02-16 04:32:48 +01:00
// TODO cmsworkflow module coupling
2010-02-16 01:44:30 +01:00
if ( Versioned :: current_stage () == 'Stage' && ! ( ClassInfo :: exists ( 'SiteTreeFutureState' ) && SiteTreeFutureState :: get_future_datetime ())) {
2010-02-16 01:41:41 +01:00
return " <a class= \" current \" > " . _t ( 'ContentController.DRAFTSITE' , 'Draft Site' ) . " </a> " ;
} else {
2010-03-24 21:33:27 +01:00
$draftPage = Versioned :: get_one_by_stage ( 'SiteTree' , 'Stage' , '"SiteTree"."ID" = ' . $page -> ID );
if ( $draftPage ) {
2012-01-31 15:51:23 +01:00
$pageLink = Convert :: raw2att ( Controller :: join_links ( $draftPage -> AbsoluteLink (), " ?stage=Stage " ));
2010-05-11 07:35:12 +02:00
return " <a href= \" $pageLink\ " class = \ " newWindow \" target= \" site \" style= \" left : -1px; \" > " . _t ( 'ContentController.DRAFTSITE' , 'Draft Site' ) . " </a> " ;
2010-03-24 21:33:27 +01:00
}
2010-02-16 01:41:41 +01:00
}
}
2010-02-16 03:26:55 +01:00
function getMessage ( $page ) {
2010-02-16 01:41:41 +01:00
if ( Versioned :: current_stage () == 'Stage' ) {
return " <div id= \" SilverStripeNavigatorMessage \" title= \" " . _t ( 'ContentControl.NOTEWONTBESHOWN' , 'Note: this message will not be shown to your visitors' ) . " \" > " . _t ( 'ContentController.DRAFTSITE' , 'Draft Site' ) . " </div> " ;
}
}
2010-02-16 03:26:55 +01:00
function getLink ( $page ) {
if ( Versioned :: current_stage () == 'Stage' ) {
2010-05-11 07:35:12 +02:00
return Controller :: join_links ( $page -> AbsoluteLink (), '?stage=Stage' );
2010-02-16 03:26:55 +01:00
}
}
2010-02-16 01:41:41 +01:00
}
2010-02-16 03:23:44 +01:00
/**
* @ package cms
* @ subpackage content
*/
2010-02-16 01:41:41 +01:00
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem {
static $priority = 30 ;
2010-02-16 03:26:55 +01:00
function getHTML ( $page ) {
2010-02-16 01:41:41 +01:00
if ( Versioned :: current_stage () == 'Live' ) {
return " <a class= \" current \" > " . _t ( 'ContentController.PUBLISHEDSITE' , 'Published Site' ) . " </a> " ;
} else {
2010-02-16 03:40:44 +01:00
$livePage = Versioned :: get_one_by_stage ( 'SiteTree' , 'Live' , '"SiteTree"."ID" = ' . $page -> ID );
if ( $livePage ) {
2012-01-31 15:51:23 +01:00
$pageLink = Convert :: raw2att ( Controller :: join_links ( $livePage -> AbsoluteLink (), " ?stage=Live " ));
2010-05-11 07:35:12 +02:00
return " <a href= \" $pageLink\ " class = \ " newWindow \" target= \" site \" style= \" left : -3px; \" > " . _t ( 'ContentController.PUBLISHEDSITE' , 'Published Site' ) . " </a> " ;
2010-02-16 03:40:44 +01:00
}
2010-02-16 01:41:41 +01:00
}
}
2010-02-16 03:26:55 +01:00
function getMessage ( $page ) {
2010-02-16 01:41:41 +01:00
if ( Versioned :: current_stage () == 'Live' ) {
return " <div id= \" SilverStripeNavigatorMessage \" title= \" " . _t ( 'ContentControl.NOTEWONTBESHOWN' , 'Note: this message will not be shown to your visitors' ) . " \" > " . _t ( 'ContentController.PUBLISHEDSITE' , 'Published Site' ) . " </div> " ;
}
}
2010-02-16 03:26:55 +01:00
function getLink ( $page ) {
if ( Versioned :: current_stage () == 'Live' ) {
2010-05-11 07:35:12 +02:00
return Controller :: join_links ( $page -> AbsoluteLink (), '?stage=Live' );
2010-02-16 03:26:55 +01:00
}
}
2010-02-16 01:41:41 +01:00
}
2010-02-16 03:23:44 +01:00
/**
* @ package cms
* @ subpackage content
*/
2010-02-16 01:41:41 +01:00
class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem {
static $priority = 40 ;
2010-02-16 03:26:55 +01:00
function getHTML ( $page ) {
2010-02-16 01:41:41 +01:00
if ( Versioned :: current_archived_date ()) {
return " <a class= \" current \" > " . _t ( 'ContentController.ARCHIVEDSITE' , 'Archived Site' ) . " </a> " ;
2010-03-24 21:33:27 +01:00
} else {
// Display the archive link if the page currently displayed in the CMS is other version than live and draft
$currentDraft = Versioned :: get_one_by_stage ( 'SiteTree' , 'Draft' , '"SiteTree"."ID" = ' . $page -> ID );
$currentLive = Versioned :: get_one_by_stage ( 'SiteTree' , 'Live' , '"SiteTree"."ID" = ' . $page -> ID );
2011-01-12 00:04:49 +01:00
if (
( ! $currentDraft || ( $currentDraft && $page -> Version != $currentDraft -> Version ))
&& ( ! $currentLive || ( $currentLive && $page -> Version != $currentLive -> Version ))
) {
2012-01-31 15:51:23 +01:00
$pageLink = Convert :: raw2att ( $page -> AbsoluteLink ());
2010-03-24 21:33:27 +01:00
return " <a href= \" $pageLink ?archiveDate= { $page -> LastEdited } \" class= \" newWindow \" target= \" site \" style= \" left : -3px; \" > " . _t ( 'ContentController.ARCHIVEDSITE' , 'Archived Site' ) . " </a> " ;
}
2010-02-16 01:41:41 +01:00
}
}
2010-02-16 03:26:55 +01:00
function getMessage ( $page ) {
2010-02-16 01:41:41 +01:00
if ( $date = Versioned :: current_archived_date ()) {
2010-03-24 21:33:27 +01:00
$dateObj = Object :: create ( 'Datetime' );
$dateObj -> setValue ( $date );
2010-02-16 01:41:41 +01:00
return " <div id= \" SilverStripeNavigatorMessage \" title= \" " . _t ( 'ContentControl.NOTEWONTBESHOWN' , 'Note: this message will not be shown to your visitors' ) . " \" > " . _t ( 'ContentController.ARCHIVEDSITEFROM' , 'Archived site from' ) . " <br> " . $dateObj -> Nice () . " </div> " ;
}
}
2010-02-16 03:26:55 +01:00
function getLink ( $page ) {
if ( $date = Versioned :: current_archived_date ()) {
return $page -> AbsoluteLink () . '?archiveDate=' . $date ;
}
}
2010-02-16 01:41:41 +01:00
}
2011-01-12 00:04:49 +01:00
?>