[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // 4 // Created on: <07-Jul-2005 10:14:34 bf> 5 // 6 // SOFTWARE NAME: eZ publish 7 // SOFTWARE RELEASE: 3.9.0 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 // 27 28 /* 29 30 Needs the following in PHP Configuration 31 32 --enable-cli 33 --enable-pcntl 34 --enable-sockets 35 36 */ 37 38 $host = "127.0.0.1"; 39 $port = 9090; 40 $ooexecutable = "openoffice.org-2.0"; 41 $maxClients = 3; 42 43 set_time_limit( 0 ); 44 45 $socket = socket_create( AF_INET, SOCK_STREAM, 0) or die( "Could not create socket\n" ); 46 $result = socket_bind( $socket, $host, $port ) or die( "Could not bind to socket\n" ); 47 $result = socket_listen( $socket, $maxClients ) or die( "Could not set up socket listener\n" ); 48 49 print( "Started OpenOffice.org deamon\n" ); 50 51 function convert_to( $sourceFileName, $convertCommand, $destinationFileName ) 52 { 53 global $ooexecutable; 54 55 print( "Converting document with $convertCommand\n" ); 56 57 switch ( $convertCommand ) 58 { 59 case "convertToPDF": 60 case "convertToOOo": 61 case "convertToDoc": 62 { 63 $result = shell_exec( $ooexecutable . " -writer 'macro:///standard.Module1." . $convertCommand . "(\"$sourceFileName\", \"$destinationFileName\")'" ); 64 }break; 65 66 default: 67 { 68 echo "Unknown command $convertCommand"; 69 return "(1)-Unknown command $convertCommand"; 70 }break; 71 } 72 73 if ( !file_exists( $destinationFileName ) ) 74 { 75 return "(3)-Unknown failure converting document "; 76 } 77 78 return true; 79 } 80 81 82 while ( $spawn = socket_accept( $socket )) 83 { 84 print( "got new connection\n" ); 85 $pid = pcntl_fork(); 86 if ( $pid != 0) 87 { 88 // In the main process 89 socket_close( $spawn ); 90 } 91 else 92 { 93 // We are in the forked child process 94 socket_write( $spawn, "eZ publish document conversion deamon\n"); 95 96 // Parse input 97 $input = socket_read( $spawn, 1024 ); 98 99 $inputParts = explode( " ", $input ); 100 101 $command = trim( $inputParts[0] ); 102 $fileName = trim( $inputParts[1] ); 103 $destName = trim( $inputParts[2] ); 104 105 106 if ( file_exists( $fileName ) ) 107 { 108 $result = convert_to( $fileName, $command, $destName ); 109 if ( !( $result === true ) ) 110 { 111 echo( "Error: $result" ); 112 socket_write( $spawn, "Error: $result" ); 113 } 114 else 115 { 116 echo( "Conversion ok. FilePath: $destName" ); 117 socket_write( $spawn, "FilePath: $destName" ); 118 } 119 } 120 else 121 { 122 echo( "Error: (2)-File not found" ); 123 socket_write( $spawn, "Error: (2)-File not found" ); 124 } 125 126 socket_close( $spawn ); 127 die('Data Recieved on child ' . posix_getpid(). "\n"); 128 } 129 } 130 131 socket_close( $socket ); 132 133 ?>
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 |