-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_book.php
155 lines (144 loc) · 5.63 KB
/
edit_book.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
*
* @package wiki
* @subpackage functions
*/
/**
* required setup
*/
require_once( '../kernel/includes/setup_inc.php' );
if( isset( $_COOKIE['book_section'] ) && $_COOKIE['book_section'] == 'o' ) {
$book_section = 'block';
} else {
$book_section = 'none';
}
$gBitSmarty->assign( 'book_section',$book_section );
include_once( LIBERTY_PKG_CLASS_PATH.'LibertyStructure.php');
include_once( WIKI_PKG_CLASS_PATH.'BitBook.php');
global $gStructure;
/**
* first pass at trying to bring books up to speed with modern perm checking
* we initialize an object here since books dont have an include
**/
// get a book instance
global $gContent;
if( @BitBase::verifyId( $_REQUEST["structure_id"] ) || @BitBase::verifyId( $_REQUEST["content_id"] ) ) {
include_once( LIBERTY_PKG_INCLUDE_PATH.'lookup_content_inc.php' );
if( empty( $gContent ) ){
$gBitSystem->fatalError( 'Error: Invalid structure id, the book you requested could not be found.' );
} elseif( empty( $_REQUEST["structure_id"] ) ) {
// we were passed a valid content_id. Make sure the root node exists, and if not, create it.
$newStructure = new LibertyStructure();
// alias => '' is a temporary setting until alias stuff has been removed
if( !$node = $newStructure->getNode( NULL, $gContent->mContentId ) ) {
$structureHash = array( 'content_id' => $gContent->mContentId, 'alias' => '' );
$_REQUEST["structure_id"] = $newStructure->storeNode( $structureHash );
} else {
$_REQUEST["structure_id"] = $node['structure_id'];
}
}
}else{
$gContent = new BitBook();
if( !empty( $_REQUEST['name'] ) ){
if( $pageId = $gContent->findByPageName( $_REQUEST['name'] ) ){
$gContent->mPageId = $pageId;
$gContent->load();
}elseif( empty( $_REQUEST["createstructure"] ) ){
$gBitSystem->fatalError( 'Error: Invalid name, the book you requested could not be found.' );
}
}
}
// end overly elaborate lookup now we can check the permission on the book.
// this is what we're really interested in doing check if we can edit the book or create one
if( $gContent->isValid() ){
$gContent->verifyUpdatePermission();
}else{
$gContent->verifyCreatePermission();
}
if( isset($_REQUEST["createstructure"]) ) {
if ((empty($_REQUEST['name']))) {
$gBitSmarty->assign('msg', tra("You must specify a name."));
$gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
die;
}
//try to add a new structure
$gContent = new BitBook();
$pageId = $gContent->findByPageName( $_REQUEST['name'] );
if( $pageId ) {
$gContent->mPageId = $pageId;
$gContent->load();
} else {
$params['title'] = $_REQUEST['name'];
$params['edit'] = '{toc}';
$gContent->store( $params );
}
if( $gContent->isValid() ) {
$gStructure = new LibertyStructure();
// alias => '' is a temporary setting until alias stuff has been removed
$structureHash = array( 'content_id' => $gContent->mContentId, 'alias' => '' );
$structure_id = $gStructure->storeNode( $structureHash );
//Cannot create a structure if a structure already exists
if (!isset($structure_id)) {
$gBitSmarty->assign('msg', $_REQUEST['name'] . " " . tra("page not added (Exists)"));
$gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
die;
}
$chapters = explode("\n", $_REQUEST["chapters"]);
foreach ($chapters as $chapter) {
$chapterName = trim($chapter);
if( !empty( $chapterName ) ) {
unset( $params );
unset( $nodeHash );
$nodeHash['parent_id'] = $structure_id;
$nodeHash['root_structure_id'] = $structure_id;
$nodeHash['level'] = 1;
//try to add a new structure
$nodePage = new BitPage();
$pageId = $nodePage->findByPageName( $chapterName );
if( $pageId ) {
$nodePage->mPageId = $pageId;
$nodePage->load();
} else {
$params['title'] = trim($chapterName);
$params['edit'] = '';
if( !$nodePage->store( $params ) ) {
$gBitSystem->fatalError( "There was an error storing the page: ".vc( $gContent->mErrors ));
}
}
$nodeHash['content_id'] = $nodePage->mContentId;
$nodeHash['after_ref_id'] = $gStructure->storeNode( $nodeHash );
}
}
header( "location: ".WIKI_PKG_URL."edit_book.php?structure_id=".$structure_id );
} else {
$gBitSmarty->assignByRef( 'errors', $gContent->mErrors );
$gBitSmarty->assign( 'name', $_REQUEST['name']);
$gBitSmarty->assign( 'chapters', $_REQUEST['chapters']);
$mid = 'bitpackage:wiki/create_book.tpl';
}
} elseif( $gContent->isValid() ) {
// Get all wiki pages for the select box
$_REQUEST['content_type_guid'] = !isset( $_REQUEST['content_type_guid'] ) ? 'bitpage' : $_REQUEST['content_type_guid'];
// verify the book permission on structure load
$verifyStructurePermission = 'p_wiki_admin_book';
// set the correct display template
$mid = 'bitpackage:wiki/edit_book.tpl';
include_once( LIBERTY_PKG_INCLUDE_PATH.'structure_edit_inc.php');
if( $gBitThemes->isAjaxRequest() ) {
$gBitSmarty->display( 'bitpackage:kernel/feedback_inc.tpl' );
}
} else {
// user is just trying to create a new book - give them the form
$gBitSystem->setBrowserTitle( 'Create Wiki Book' );
$mid = 'bitpackage:wiki/create_book.tpl';
}
$gBitSystem->setBrowserTitle( !empty($gStructure) && $gStructure->isValid() ? 'Edit Wiki Book:'.$gStructure->getField( 'title' ) : NULL );
// Display the template
$gBitSystem->display( $mid , NULL, array( 'display_mode' => 'edit' ));
?>