forked from vlad-ghita/entry_nav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
100 lines (79 loc) · 2.94 KB
/
extension.driver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
Class Extension_Entry_Nav extends Extension
{
/*------------------------------------------------------------------------------------------------*/
/* Delegates */
/*------------------------------------------------------------------------------------------------*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'dInitaliseAdminPageHead'
),
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => 'dAdminPagePreGenerate'
)
);
}
public function dInitaliseAdminPageHead(){
$callback = Administration::instance()->getPageCallback();
// append assets
if( $callback['context']['page'] == 'edit' ){
Administration::instance()->Page->addStylesheetToHead( URL.'/extensions/entry_nav/assets/entry_nav.publish_single.css', "screen" );
}
}
public function dAdminPagePreGenerate($context){
$callback = Administration::instance()->getPageCallback();
if( $callback['context']['page'] === 'edit' ){
/** @var $cxt XMLElement */
$cxt = $context['oPage']->Context;
if( !$cxt instanceof XMLElement ) return;
$actions = $cxt->getChildByName( 'ul', 0 );
// append list of actions if missing
if( !$actions instanceof XMLElement ){
$ul = new XMLelement('ul', null, array('class' => 'actions'));
$cxt->appendChild( $ul );
$actions = $cxt->getChildByName( 'ul', 0 );
}
// fetch entries
$section_id = SectionManager::fetchIDFromHandle( $callback['context']['section_handle'] );
$section = SectionManager::fetch( $section_id );
EntryManager::setFetchSorting( $section->getSortingField(), $section->getSortingOrder() );
$entries = EntryManager::fetch( null, $section_id, null, null, null, null, null, false, false );
// get next and prev
$entry_id = $prev_id = $next_id = $callback['context']['entry_id'];
$count = count( $entries );
for( $i = 0 ; $i < $count ; $i++ )
if( $entries[$i]['id'] == $entry_id ){
$prev_id = $i == 0 ? $entries[$count - 1]['id'] : $entries[$i - 1]['id'];
$next_id = $i == $count - 1 ? $entries[0]['id'] : $entries[$i + 1]['id'];
break;
}
if( $prev_id == $entry_id && $next_id == $entry_id ) return;
// add buttons
$li = new XMLelement('li', null, array('class' => 'entry-nav'));
if( $prev_id !== $entry_id )
$li->appendChild( Widget::Anchor(
__( '← Previous' ),
SYMPHONY_URL.$callback['pageroot'].'edit/'.$prev_id,
null,
'button entry-nav-prev',
null,
array('accesskey' => 'z')
) );
if( $next_id !== $entry_id )
$li->appendChild( Widget::Anchor(
__( 'Next →' ),
SYMPHONY_URL.$callback['pageroot'].'edit/'.$next_id,
null,
'button entry-nav-next',
null,
array('accesskey' => 'x')
) );
$actions->appendChild( $li );
}
}
}