wiki
[ class tree: wiki ] [ index: wiki ] [ all elements ]

Source for file edit_book.php

Documentation is available at edit_book.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2004 bitweaver.org
  4.  * Copyright (c) 2003 tikwiki.org
  5.  * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  6.  * All Rights Reserved. See below for details and a complete list of authors.
  7.  * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  8.  *
  9.  * @package wiki
  10.  * @subpackage functions
  11.  */
  12.  
  13. /**
  14.  * required setup
  15.  */
  16. require_once( '../kernel/setup_inc.php' );
  17.  
  18. if( isset( $_COOKIE['book_section'] ) && $_COOKIE['book_section'] == 'o' ) {
  19.     $book_section = 'block';
  20. } else {
  21.     $book_section = 'none';
  22. }
  23. $gBitSmarty->assign( 'book_section',$book_section );
  24.  
  25. include_once( LIBERTY_PKG_PATH.'LibertyStructure.php');
  26. include_once( WIKI_PKG_PATH.'BitBook.php');
  27.  
  28. global $gStructure;
  29.  
  30. /**
  31.  * first pass at trying to bring books up to speed with modern perm checking
  32.  * we initialize an object here since books dont have an include
  33.  **/
  34.  
  35. // get a book instance
  36. global $gContent;
  37. if( @BitBase::verifyId( $_REQUEST["structure_id"] ) || @BitBase::verifyId( $_REQUEST["content_id"] ) ) {
  38.     include_once( LIBERTY_PKG_PATH.'lookup_content_inc.php' );
  39.     if( empty( $gContent ) ){
  40.         $gBitSystem->fatalError( 'Error: Invalid structure id, the book you requested could not be found.' );
  41.     } elseif( empty( $_REQUEST["structure_id"] ) ) {
  42.         // we were passed a valid content_id. Make sure the root node exists, and if not, create it.
  43.         $newStructure = new LibertyStructure();
  44.         // alias => '' is a temporary setting until alias stuff has been removed
  45.         if( !$node = $newStructure->getNode( NULL, $gContent->mContentId ) ) {
  46.             $structureHash = array( 'content_id' => $gContent->mContentId, 'alias' => '' );
  47.             $_REQUEST["structure_id"] = $newStructure->storeNode( $structureHash );
  48.         } else {
  49.             $_REQUEST["structure_id"] = $node['structure_id'];
  50.         }
  51.     }
  52. }else{
  53.     $gContent = new BitBook();
  54.     if( !empty( $_REQUEST['name'] ) ){
  55.         if( $pageId = $gContent->findByPageName( $_REQUEST['name'] ) ){
  56.             $gContent->mPageId = $pageId;
  57.             $gContent->load();
  58.         }elseif( empty( $_REQUEST["createstructure"] ) ){
  59.             $gBitSystem->fatalError( 'Error: Invalid name, the book you requested could not be found.' );
  60.         }
  61.     }
  62. }
  63. // end overly elaborate lookup now we can check the permission on the book.
  64.  
  65. // this is what we're really interested in doing check if we can edit the book or create one
  66. if( $gContent->isValid() ){
  67.     $gContent->verifyUpdatePermission();
  68. }else{
  69.     $gContent->verifyCreatePermission();
  70. }
  71.  
  72. if( isset($_REQUEST["createstructure"]) ) {
  73.     if ((empty($_REQUEST['name']))) {
  74.         $gBitSmarty->assign('msg', tra("You must specify a name."));
  75.         $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
  76.         die;
  77.     }
  78.  
  79.     //try to add a new structure
  80.     $gContent = new BitBook();
  81.     $pageId = $gContent->findByPageName( $_REQUEST['name'] );
  82.     if( $pageId ) {
  83.         $gContent->mPageId = $pageId;
  84.         $gContent->load();
  85.     } else {
  86.         $params['title'] = $_REQUEST['name'];
  87.         $params['edit'] = '{toc}';
  88.         $gContent->store( $params );
  89.     }
  90.  
  91.     if( $gContent->isValid() ) {
  92.         $gStructure = new LibertyStructure();
  93.         // alias => '' is a temporary setting until alias stuff has been removed
  94.         $structureHash = array( 'content_id' => $gContent->mContentId, 'alias' => '' );
  95.         $structure_id = $gStructure->storeNode( $structureHash );
  96.         //Cannot create a structure if a structure already exists
  97.         if (!isset($structure_id)) {
  98.             $gBitSmarty->assign('msg', $_REQUEST['name'] . " " . tra("page not added (Exists)"));
  99.             $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'edit' ));
  100.             die;
  101.         }
  102.  
  103.         $chapters = explode("\n", $_REQUEST["chapters"]);
  104.         foreach ($chapters as $chapter) {
  105.             $chapterName = trim($chapter);
  106.             if( !empty( $chapterName ) ) {
  107.                 unset( $params );
  108.                 unset( $nodeHash );
  109.                 $nodeHash['parent_id'] = $structure_id;
  110.                 $nodeHash['root_structure_id'] = $structure_id;
  111.                 $nodeHash['level'] = 1;
  112.                 //try to add a new structure
  113.                 $nodePage = new BitPage();
  114.                 $pageId = $nodePage->findByPageName( $chapterName );
  115.                 if( $pageId ) {
  116.                     $nodePage->mPageId = $pageId;
  117.                     $nodePage->load();
  118.                 } else {
  119.                     $params['title'] = trim($chapterName);
  120.                     $params['edit'] = '';
  121.                     if( !$nodePage->store( $params ) ) {
  122.                         $gBitSystem->fatalError( "There was an error storing the page: ".vc( $gContent->mErrors ));
  123.                     }
  124.                 }
  125.                 $nodeHash['content_id'] = $nodePage->mContentId;
  126.                 $nodeHash['after_ref_id'] = $gStructure->storeNode( $nodeHash );
  127.             }
  128.         }
  129.         header( "location: ".WIKI_PKG_URL."edit_book.php?structure_id=".$structure_id );
  130.     } else {
  131.         $gBitSmarty->assign_by_ref( 'errors', $gContent->mErrors );
  132.         $gBitSmarty->assign( 'name', $_REQUEST['name']);
  133.         $gBitSmarty->assign( 'chapters', $_REQUEST['chapters']);
  134.         $mid = 'bitpackage:wiki/create_book.tpl';
  135.     }
  136. } elseif( $gContent->isValid() ) {
  137.     // Get all wiki pages for the select box
  138.     $_REQUEST['content_type_guid'] = !isset( $_REQUEST['content_type_guid'] ) ? 'bitpage' : $_REQUEST['content_type_guid'];
  139.     // verify the book permission on structure load
  140.     $verifyStructurePermission = 'p_wiki_admin_book';
  141.  
  142.     // set the correct display template
  143.     $mid = 'bitpackage:wiki/edit_book.tpl';
  144.     include_once( LIBERTY_PKG_PATH.'edit_structure_inc.php');
  145.     if( $gBitThemes->isAjaxRequest() ) {
  146.         $gBitSmarty->display( 'bitpackage:kernel/feedback_inc.tpl' );
  147.     }
  148. } else {
  149.     // user is just trying to create a new book - give them the form
  150.     $gBitSystem->setBrowserTitle( 'Create Wiki Book' );
  151.     $mid = 'bitpackage:wiki/create_book.tpl';
  152. }
  153. $gBitSystem->setBrowserTitle( !empty($gStructure) && $gStructure->isValid() ? 'Edit Wiki Book:'.$gStructure->getField( 'title' ) : NULL );
  154. // Display the template
  155. $gBitSystem->display( $mid , NULL, array( 'display_mode' => 'edit' ));
  156. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:26 +0000 by phpDocumentor 1.5.0-lsces