[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/extension/ezodf/modules/ezodf/ -> export.php (source)

   1  <?php
   2  //
   3  // Created on: <10-Nov-2004 11:42:23 bf>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( "kernel/common/template.php" );
  28  
  29  include_once ( 'kernel/classes/ezcontentobject.php' );
  30  include_once ( 'lib/ezlocale/classes/ezdatetime.php' );
  31  
  32  include_once ( "kernel/classes/ezcontentbrowse.php" );
  33  
  34  include_once ( "extension/ezodf/modules/ezodf/ezooconverter.php" );
  35  
  36  
  37  $http =& eZHTTPTool::instance();
  38  $module =& $Params["Module"];
  39  $NodeID = $Params['NodeID'];
  40  $exportTypeParam = $Params['ExportType'];
  41  
  42  $tpl =& templateInit();
  43  
  44  $success = true;
  45  
  46  if ( $http->hasPostVariable( "ExportButton" ) )
  47  {
  48      eZContentBrowse::browse( array( 'action_name' => 'OOPlace',
  49                                      'description_template' => 'design:ezodf/browse_place.tpl',
  50                                      'content' => array(),
  51                                      'from_page' => '/ezodf/export/',
  52                                      'cancel_page' => '/ezodf/export/' ),
  53                               $module );
  54      return;
  55  }
  56  
  57  $doExport = false;
  58  if ( $module->isCurrentAction( 'OOPlace' ) )
  59  {
  60      // We have the file and the placement. Do the actual import.
  61      $selectedNodeIDArray = eZContentBrowse::result( 'OOPlace' );
  62      $nodeID = $selectedNodeIDArray[0];
  63      $doExport = true;
  64  }
  65  
  66  if ( $http->hasPostVariable( "NodeID" ) )
  67  {
  68      $nodeID = $http->postVariable( "NodeID" );
  69      $doExport = true;
  70  }
  71  else if ( is_numeric( $NodeID ) )
  72  {
  73      $nodeID = $NodeID;
  74      $doExport = true;
  75  }
  76  
  77  $exportType = false;
  78  if ( $http->hasPostVariable( "ExportType" ) )
  79  {
  80      $type = $http->postVariable( "ExportType" );
  81  
  82      if ( $type == "PDF" or $type == "Word" )
  83      {
  84          $exportType = $type;
  85      }
  86      else
  87      {
  88          $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"Destination file format not supported" ) );
  89          $success = false;
  90      }
  91  }
  92  else if ( $exportTypeParam == "PDF" or $exportTypeParam == "Word" )
  93  {
  94      $exportType = $exportTypeParam;
  95  }
  96  else if ( strlen( trim ( $exportTypeParam) ) != 0 )
  97  {
  98      $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"Destination file format not supported" ) );
  99      $success = false;
 100  }
 101  
 102  $ooINI =& eZINI::instance( 'odf.ini' );
 103  //$tmpDir = $ooINI->variable( 'ODFSettings', 'TmpDir' );
 104  $tmpDir = getcwd() . "/" . eZSys::cacheDirectory();
 105  
 106  if ( $doExport == true )
 107  {
 108  
 109      if ( is_numeric( $nodeID ) )
 110      {
 111  
 112          $node = eZContentObjectTreeNode::fetch( $nodeID );
 113  
 114          // Check if we have read access to this node
 115          if ( $node && $node->canRead() )
 116          {
 117              // Do the actual eZ publish export
 118              $fileName = eZOOConverter::objectToOO( $nodeID );
 119  
 120              if ( !is_array( $fileName ) )
 121              {
 122                  $nodeName = $node->attribute( 'name' );
 123  
 124                  $originalFileName = $nodeName . ".odt";
 125                  $contentType = "application/vnd.oasis.opendocument.text";
 126  
 127                  include_once ( 'lib/ezi18n/classes/ezchartransform.php' );
 128                  $trans =& eZCharTransform::instance();
 129                  $nodeName = $trans->transformByGroup( $nodeName, 'urlalias' );
 130  
 131                  $uniqueStamp = md5( mktime() );
 132  
 133                  $server = $ooINI->variable( "ODFImport", "OOConverterAddress" );
 134                  $port = $ooINI->variable( "ODFImport", "OOConverterPort" );
 135  
 136                  switch ( $exportType )
 137                  {
 138                      case "PDF" :
 139                      {
 140                          if ( ( $result = deamonConvert( $server, $port, realpath( $fileName ), "convertToPDF", $tmpDir . "/ooo_converted_$uniqueStamp.pdf" ) ) )
 141                          {
 142                              $originalFileName = $nodeName . ".pdf";
 143                              $contentType = "application/pdf";
 144                              $fileName = $tmpDir . "/ooo_converted_$uniqueStamp.pdf";
 145                          }
 146                          else
 147                          {
 148                              $success = false;
 149                              $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"PDF conversion failed" ) );
 150                          }
 151  
 152                      }break;
 153  
 154                      case "Word" :
 155                      {
 156                          if ( ( $result = deamonConvert( $server, $port, realpath( $fileName ), "convertToDoc", $tmpDir . "/ooo_converted_$uniqueStamp.doc" ) ) )
 157                          {
 158                              $originalFileName = $nodeName . ".doc";
 159                              $contentType = "application/ms-word";
 160                              $fileName = $tmpDir . "/ooo_converted_$uniqueStamp.doc";
 161                          }
 162                          else
 163                          {
 164                              $success = false;
 165                              $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"Word conversion failed" ) );
 166                          }
 167  
 168                      }break;
 169  
 170                  }
 171  
 172              }
 173              else
 174              {
 175                  $tpl->setVariable( "error_string", $fileName[1] );
 176                  $success = false;
 177              }
 178          }
 179          else
 180          {
 181              $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"Unable to fetch node, or no read access" ) );
 182              $success = false;
 183          }
 184  
 185          if ( $success )
 186          {
 187              $contentLength = filesize( $fileName );
 188              if ( $contentLength > 0 )
 189              {
 190  
 191                  // Download the file
 192                  header( "Pragma: " );
 193                  header( "Cache-Control: " );
 194                  /* Set cache time out to 10 minutes, this should be good enough to work around an IE bug */
 195                  header( "Expires: ". gmdate('D, d M Y H:i:s', time() + 600) . 'GMT');
 196                  header( "Content-Length: $contentLength" );
 197                  header( "Content-Type: $contentType" );
 198                  header( "X-Powered-By: eZ publish" );
 199                  header( "Content-disposition: attachment; filename=\"$originalFileName\"" );
 200                  header( "Content-Transfer-Encoding: binary" );
 201                  header( "Accept-Ranges: bytes" );
 202  
 203                  $fh = fopen( "$fileName", "rb" );
 204                  if ( $fileOffset )
 205                  {
 206                      fseek( $fh, $fileOffset );
 207                  }
 208  
 209                  ob_end_clean();
 210                  fpassthru( $fh );
 211                  fclose( $fh );
 212                  fflush();
 213  
 214                  unlink( $fileName );
 215                  eZExecution::cleanExit();
 216              }
 217              else
 218              {
 219                  $tpl->setVariable( "error_string", ezi18n( 'extension/ezodf/export/error',"Unable to open file %1 on server side", null, array( $fileName ) ) );
 220              }
 221          }
 222      }
 223  }
 224  
 225  $Result = array();
 226  $Result['content'] =& $tpl->fetch( "design:ezodf/export.tpl" );
 227  $Result['path'] = array( array( 'url' => '/ezodf/export/',
 228                                  'text' => ezi18n( 'extension/ezodf', 'OpenOffice.org export' ) ) );
 229  
 230  
 231  /*!
 232        Connects to the eZ publish document conversion deamon and converts the document to specified format
 233  */
 234  function deamonConvert( $server, $port, $sourceFile, $conversionCommand, $destFile )
 235  {
 236      $fp = fsockopen( $server,
 237                       $port,
 238                       $errorNR,
 239                       $errorString,
 240                       0 );
 241  
 242      if ( $fp )
 243      {
 244          $welcome = fread( $fp, 1024 );
 245  
 246          $welcome = trim( $welcome );
 247          if ( $welcome == "eZ publish document conversion deamon" )
 248          {
 249              $commandString = "$conversionCommand $sourceFile $destFile";
 250              fputs( $fp, $commandString, strlen( $commandString ) );
 251  
 252              $result = fread( $fp, 1024 );
 253              $result = trim( $result );
 254          }
 255          fclose( $fp );
 256  
 257          return $result;
 258      }
 259      return false;
 260  }
 261  
 262  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7