[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // eZSetup - init part initialization 4 // 5 // Created on: <29-Oct-2003 14:49:54 kk> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 define( 'EZ_PDFEXPORT_GENERATE_STRING', 'generate' ); 30 31 include_once ( 'kernel/common/template.php' ); 32 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 33 include_once ( 'kernel/classes/ezpdfexport.php' ); 34 include_once ( 'lib/eztemplate/classes/eztemplateincludefunction.php' ); 35 36 $Module =& $Params['Module']; 37 $http =& eZHTTPTool::instance(); 38 39 if ( isset( $Params['PDFGenerate'] ) && $Params['PDFGenerate'] == EZ_PDFEXPORT_GENERATE_STRING ) 40 { 41 $pdfExport = eZPDFExport::fetch( $Params['PDFExportID'] ); 42 if ( $pdfExport && $pdfExport->attribute( 'status' ) == EZ_PDFEXPORT_CREATE_ONFLY ) // only generate OnTheFly if status set correctly 43 { 44 include_once ( 'lib/ezutils/classes/ezexecution.php' ); 45 generatePDF( $pdfExport ); 46 eZExecution::cleanExit(); 47 } 48 return; 49 } 50 51 if ( isset( $Params['PDFExportID'] ) ) 52 { 53 $pdfExport = eZPDFExport::fetch( $Params['PDFExportID'], true, EZ_PDFEXPORT_VERSION_DRAFT ); 54 55 if ( $pdfExport ) 56 { 57 include_once ( 'lib/ezlocale/classes/ezdatetime.php' ); 58 59 $user =& eZUser::currentUser(); 60 $contentIni =& eZIni::instance( 'content.ini' ); 61 $timeOut = $contentIni->variable( 'PDFExportSettings', 'DraftTimeout' ); 62 if ( $pdfExport->attribute( 'modifier_id' ) != $user->attribute( 'contentobject_id' ) && 63 $pdfExport->attribute( 'modified' ) + $timeOut > time() ) 64 { 65 // TODO: In 3.6 66 // // locked editing 67 // $tpl =& templateInit(); 68 // $tpl->setVariable ... 69 // $Result = array(); 70 // $Result['content'] =& $tpl->fetch( 'design:pdf/edit_denied.tpl' ); 71 // $Result['path'] = ... 72 // return $Result; 73 } 74 else if ( $timeOut > 0 && $pdfExport->attribute( 'modified' ) + $timeOut < time() ) 75 { 76 $pdfExport->remove(); 77 $pdfExport = false; 78 } 79 } 80 if ( !$pdfExport ) 81 { 82 $pdfExport = eZPDFExport::fetch( $Params['PDFExportID'] ); 83 if( !$pdfExport ) // user requested a non existent export 84 { 85 return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' ); 86 } 87 $pdfExport->setAttribute( 'version', EZ_PDFEXPORT_VERSION_DRAFT ); 88 $pdfExport->store(); 89 } 90 } 91 else 92 { 93 include_once ( 'kernel/classes/ezpdfexport.php' ); 94 include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" ); 95 $user =& eZUser::currentUser(); 96 97 $pdfExport = eZPDFExport::create( $user->attribute( 'contentobject_id' ) ); 98 $pdfExport->store(); 99 } 100 101 if ( $http->hasPostVariable( 'SelectedNodeIDArray' ) && !$http->hasPostVariable( 'BrowseCancelButton' ) ) // Get Source node ID from browse 102 { 103 $selectedNodeIDArray = $http->postVariable( 'SelectedNodeIDArray' ); 104 $pdfExport->setAttribute( 'source_node_id', $selectedNodeIDArray[0] ); 105 $pdfExport->store(); 106 } 107 108 $validation = array(); 109 $inputValidated = true; 110 111 if ( $Module->isCurrentAction( 'BrowseSource' ) || // Store PDF export objects 112 $Module->isCurrentAction( 'Export' ) ) 113 { 114 $pdfExport->setAttribute( 'title', $Module->actionParameter( 'Title' ) ); 115 $pdfExport->setAttribute( 'show_frontpage', $Module->hasActionParameter( 'DisplayFrontpage' ) ? 1 : 0 ); 116 $pdfExport->setAttribute( 'intro_text', $Module->actionParameter( 'IntroText' ) ); 117 $pdfExport->setAttribute( 'sub_text', $Module->actionParameter( 'SubText' ) ); 118 $pdfExport->setAttribute( 'export_structure', $Module->actionParameter( 'ExportType' ) ); 119 if ( $Module->actionParameter( 'ExportType' ) == 'tree' && $Module->hasActionParameter( 'ClassList' ) ) 120 $pdfExport->setAttribute( 'export_classes', implode( ':', $Module->actionParameter( 'ClassList' ) ) ); 121 $pdfExport->setAttribute( 'pdf_filename', basename( $Module->actionParameter( 'DestinationFile' ) ) ); 122 $pdfExport->setAttribute( 'status', ( basename( $Module->actionParameter( 'DestinationType' ) ) != 'download' ) ? 123 EZ_PDFEXPORT_CREATE_ONCE : EZ_PDFEXPORT_CREATE_ONFLY ); 124 125 if ( $Module->isCurrentAction( 'Export' ) ) 126 { 127 $pdfExport->setAttribute( 'source_node_id', $Module->actionParameter( 'SourceNode' ) ); 128 129 if ( $pdfExport->attribute( 'status' ) == EZ_PDFEXPORT_CREATE_ONCE 130 && $pdfExport->countGeneratingOnceExports() > 0 ) 131 { 132 $validation[ 'placement' ][] = array( 'text' => ezi18n( 'kernel/pdf', 'An export with such filename already exists.' ) ); 133 $validation[ 'processed' ] = true; 134 $inputValidated = false; 135 } 136 } 137 138 if ( $inputValidated ) 139 { 140 $pdfExport->store(); 141 } 142 } 143 144 $setWarning = false; // used to set missing options during export 145 146 if ( $Module->isCurrentAction( 'BrowseSource' ) ) 147 { 148 include_once ( 'kernel/classes/ezcontentbrowse.php' ); 149 eZContentBrowse::browse( array( 'action_name' => 'ExportSourceBrowse', 150 'description_template' => 'design:content/browse_export.tpl', 151 'from_page' => '/pdf/edit/'. $pdfExport->attribute( 'id' ) ), 152 $Module ); 153 } 154 else if ( $Module->isCurrentAction( 'Export' ) && $inputValidated ) 155 { 156 // remove the old file ( user may changed the filename ) 157 $originalPdfExport = eZPDFExport::fetch( $Params['PDFExportID'] ); 158 if ( $originalPdfExport && $originalPdfExport->attribute( 'status' ) == EZ_PDFEXPORT_CREATE_ONCE ) 159 { 160 $filename =& $originalPdfExport->attribute( 'filepath' ); 161 if ( file_exists( $filename ) ) 162 { 163 unlink( $filename ); 164 } 165 } 166 167 if ( $pdfExport->attribute( 'status' ) == EZ_PDFEXPORT_CREATE_ONCE ) 168 { 169 generatePDF( $pdfExport, $pdfExport->attribute( 'filepath' ) ); 170 $pdfExport->store( true ); 171 return $Module->redirect( 'pdf', 'list' ); 172 } 173 else 174 { 175 $pdfExport->store( true ); 176 return $Module->redirect( 'pdf', 'list' ); 177 } 178 } 179 else if ( $Module->isCurrentAction( 'Discard' ) ) 180 { 181 $pdfExport->remove(); 182 return $Module->redirect( 'pdf', 'list' ); 183 } 184 185 $tpl =& templateInit(); 186 187 $tpl->setVariable( 'set_warning', $setWarning ); 188 189 // Populate site access list 190 $config =& eZINI::instance( 'site.ini' ); 191 $siteAccess = $config->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' ); 192 193 // Get Classes and class attributes 194 $classArray = eZContentClass::fetchList(); 195 196 $tpl->setVariable( 'pdf_export', $pdfExport ); 197 $tpl->setVariable( 'export_type' , $pdfExport->attribute( 'status' ) ); 198 $tpl->setVariable( 'export_site_access', $siteAccess ); 199 $tpl->setVariable( 'export_class_array', $classArray ); 200 $tpl->setVariable( 'pdfexport_list', eZPDFExport::fetchList() ); 201 202 if ( !$inputValidated ) 203 { 204 $tpl->setVariable( 'validation', $validation ); 205 } 206 207 $Result = array(); 208 $Result['content'] =& $tpl->fetch( 'design:pdf/edit.tpl' ); 209 $Result['path'] = array( array( 'url' => false, 210 'text' => ezi18n( 'pdf/edit', 'PDF Export' ) ) ); 211 212 /*! 213 \generate and output PDF data, either to file or stream 214 215 \param PDF export object 216 \param toFile, false if generate to stream, $ 217 filename if generate to file 218 */ 219 function generatePDF( &$pdfExport, $toFile = false ) 220 { 221 if ( $pdfExport == null ) 222 return; 223 224 $node = $pdfExport->attribute( 'source_node' ); 225 if ( $node ) 226 { 227 $object =& $node->attribute( 'object' ); 228 229 $tpl =& templateInit(); 230 231 $tpl->setVariable( 'node', $node ); 232 $tpl->setVariable( 'generate_toc', 1 ); 233 234 $tpl->setVariable( 'tree_traverse', 235 $pdfExport->attribute( 'export_structure' ) == 'tree' ? 1 : 0 ); 236 $tpl->setVariable( 'class_array', explode( ':', $pdfExport->attribute( 'export_classes' ) ) ); 237 $tpl->setVariable( 'show_frontpage', $pdfExport->attribute( 'show_frontpage' ) ); 238 if ( $pdfExport->attribute( 'show_frontpage' ) == 1 ) 239 { 240 $tpl->setVariable( 'intro_text', $pdfExport->attribute( 'intro_text' ) ); 241 $tpl->setVariable( 'sub_intro_text', $pdfExport->attribute( 'sub_text' ) ); 242 } 243 244 if ( $toFile === false ) 245 { 246 $tpl->setVariable( 'generate_stream', 1 ); 247 } 248 else 249 { 250 $tpl->setVariable( 'generate_file', 1 ); 251 $tpl->setVariable( 'filename', $toFile ); 252 } 253 254 $res =& eZTemplateDesignResource::instance(); 255 $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), 256 array( 'node', $node->attribute( 'node_id' ) ), 257 array( 'parent_node', $node->attribute( 'parent_node_id' ) ), 258 array( 'class', $object->attribute( 'contentclass_id' ) ), 259 array( 'class_identifier', $object->attribute( 'class_identifier' ) ), 260 array( 'depth', $node->attribute( 'depth' ) ), 261 array( 'url_alias', $node->attribute( 'url_alias' ) ) 262 ) ); 263 264 $textElements = array(); 265 $uri = 'design:node/view/pdf.tpl'; 266 $tpl->setVariable( 'pdf_root_template', 1 ); 267 eZTemplateIncludeFunction::handleInclude( $textElements, $uri, $tpl, '', '' ); 268 $pdf_definition = implode( '', $textElements ); 269 270 $pdf_definition = str_replace( array( ' ', 271 "\r\n", 272 "\t", 273 "\n" ), 274 '', 275 $pdf_definition ); 276 277 $tpl->setVariable( 'pdf_definition', $pdf_definition ); 278 279 $uri = 'design:node/view/execute_pdf.tpl'; 280 $textElements = ''; 281 eZTemplateIncludeFunction::handleInclude( $textElements, $uri, $tpl, '', '' ); 282 } 283 } 284 285 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |