Changeset 3895
- Timestamp:
- 05/02/07 15:36:27 (6 years ago)
- Files:
-
- plugins/sfOpenOfficePlugin/README (modified) (7 diffs)
- plugins/sfOpenOfficePlugin/config/config.php (modified) (1 diff)
- plugins/sfOpenOfficePlugin/config/ooffice-unix-env.sh (modified) (1 diff)
- plugins/sfOpenOfficePlugin/data/tasks/sfPakeOpenOffice.php (modified) (1 diff)
- plugins/sfOpenOfficePlugin/data/transformations/ods.xsl (added)
- plugins/sfOpenOfficePlugin/data/transformations/odt.xsl (moved) (moved from plugins/sfOpenOfficePlugin/data/transformations/ooo.odt.xsl) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfOpenOfficePlugin/README
r3892 r3895 1 1 = sfOpenOffice Plugin = 2 3 [[PageOutline]]4 2 5 3 == Authors == … … 19 17 This is the ultimate solution for server side report generation! Stop searching and continue to read. Imagine making beatiful reports with dynamic data and charts, easy paging, custom images and more. Just use the !OpenOffice.org suite and add easy PHP code to turn the document dynamic. The integration with Symfony resembles typical templates. Therefore learning to use this plugin is so straightforward as coding Symfony templates. You also have the power to choose the output format such as PDF, Microsoft Word or Excel and much more. 20 18 21 Check out the example on attachments. The !OpenOffice document report.odt resulted in report.pdf. The action executeReport only sets the variable $items.19 Check out the example on attachments. The !OpenOffice.org document report.odt resulted in report.pdf. The action executeReport only sets the variable $items. 22 20 23 21 == Motivation == … … 27 25 == How it works == 28 26 29 At development time, instead of writing HTML/PHP templates you write !OpenOffice documents with PHP code. See tutorial to learn how to write PHP code in !OpenOffice documents. Then, in order to make the document a template, a new task needs to be executed. Much like propel-build-model, the new task ooffice-create-document will preprocess the !OpenOfficedocument to ease runtime document generation.27 At development time, instead of writing HTML/PHP templates you write !OpenOffice.org documents with PHP code. See tutorial to learn how to write PHP code in !OpenOffice.org documents. Then, in order to make the document a template, a new task needs to be executed. Much like propel-build-model, the new task ooffice-create-document will preprocess the !OpenOffice.org document to ease runtime document generation. 30 28 31 !OpenOffice zips the document content, style and definitions into one file (for instance ODT). One of those files is content.xml which will have the document body (with our styled PHP code). So the new task will unzip it and transform all files inside with a XSLT so that all styled PHP code becomes markup PHP code (which can be evaluated). The task also creates a empty view class associated with the document action. This way the action won't result in a sfPHPView but in a sfOpenOfficeDocumentView.29 !OpenOffice.org zips the document content, style and definitions into one file (for instance ODT). One of those files is content.xml which will have the document body (with our styled PHP code). So the new task will unzip it and transform all files inside with a XSLT so that all styled PHP code becomes markup PHP code (which can be evaluated). The task also creates a empty view class associated with the document action. This way the action won't result in a sfPHPView but in a sfOpenOfficeDocumentView. 32 30 33 At runtime all the work is done in the sfOpenOfficeDocumentView. It grabs all the variables defined in the action (much like sfPHPView) and executes all the files mentioned above. Then it zips the executed files (which is an !OpenOffice document with dynamic data) and ask !OpenOfficeto do its magic, for instance, rendering the document to PDF. The result can be sent to client, server printer (for office intranets or online store orders), email or just saved.31 At runtime all the work is done in the sfOpenOfficeDocumentView. It grabs all the variables defined in the action (much like sfPHPView) and executes all the files mentioned above. Then it zips the executed files (which is an !OpenOffice.org document with dynamic data) and ask !OpenOffice.org to do its magic, for instance, rendering the document to PDF. The result can be sent to client, server printer (for office intranets or online store orders), email or just saved. 34 32 35 33 == Requirements == 36 34 37 * !OpenOffice 2.0.4 or superior35 * !OpenOffice.org 2.0.4 or superior 38 36 * Shell zip/unzip commands (configurable on app.yml) 39 * Xvfb to allow running !OpenOffice from PHP (I'm not a system administrator so I ask, if you have a better solution please email me)37 * Xvfb to allow running !OpenOffice.org from PHP (I'm not a system administrator so I ask, if you have a better solution please email me) 40 38 41 39 == Setup == 40 41 First of all take a look to plugins/sfOpenOfficePlugin/config/ooffice-*-env.* scripts. If those settings doesn't match your system then copy the corresponding file to the project config folder and change the necessary settings. 42 43 This plugin is shipped with a module to setup and test the !OpenOffice.org. This module gives you detailed instructions step by step. So , in order to use it you must enable it on settings.yml: 42 44 43 45 {{{ … … 72 74 === Linux === 73 75 74 In order to setup correctly !OpenOffice , you need to activate the license. We suggest that you run OpenOffice in X with the user apache.76 In order to setup correctly !OpenOffice.org, you need to activate the license. We suggest that you run OpenOffice in X with the user apache. 75 77 76 78 Change to the apache user (here apache): … … 90 92 }}} 91 93 92 Then, just run !OpenOffice in display 994 Then, just run !OpenOffice.org in display 9 93 95 {{{ 94 96 $PATH_TO_OOFICE_BIN_DIR/soffice -display :9 … … 115 117 == Tutorial == 116 118 117 So you have an !OpenOffice document and you want to make it dynamic. First of all let's assume we are working in the application app and in the module mod. The document we created is report.odt. Now create the documents directory under the module directory:119 So you have an !OpenOffice.org document and you want to make it dynamic. First of all let's assume we are working in the application app and in the module mod. The document we created is report.odt. Now create the documents directory under the module directory: 118 120 119 121 {{{ … … 146 148 If the actions returns other value than sfView::SUCCESS then it won't generate the document. It will fall back to the regular template. For instance, if the return value is sfView::ERROR then it will result in the template reportError.php. 147 149 148 Now we are ready to go. If you try http://servername/app_dev.php/mod/report it should open the PDF document. PDF is the default format but you can change to any format supported by !OpenOffice in the view class (explained later).150 Now we are ready to go. If you try http://servername/app_dev.php/mod/report it should open the PDF document. PDF is the default format but you can change to any format supported by !OpenOffice.org in the view class (explained later). 149 151 150 152 == Issues == 151 153 152 For each document generation the !OpenOffice is executed by the apache user in a virtual X. The overhead of this schema is the !OpenOffice startup, which takes few seconds. We tested other schema where the the virtual X is static and there is one instance of !OpenOfficerunning. The tests showed great performance improvement. So its a matter of time to get this schema easy to configure. Remember that this is not a Symfony issue but a administration issue. Fell free to drop here suggestions.154 For each document generation the !OpenOffice.org is executed by the apache user in a virtual X. The overhead of this schema is the !OpenOffice.org startup, which takes few seconds. We tested other schema where the the virtual X is static and there is one instance of !OpenOffice.org running. The tests showed great performance improvement. So its a matter of time to get this schema easy to configure. Remember that this is not a Symfony issue but a administration issue. Fell free to drop here suggestions. 153 155 154 156 == Future == plugins/sfOpenOfficePlugin/config/config.php
r3891 r3895 1 1 <?php 2 2 3 $ os = substr(strtolower(PHP_OS), 0, 3);3 $phpos = substr(strtolower(PHP_OS), 0, 3); 4 4 5 if( $ os == 'win')5 if( $phpos == 'win') 6 6 { 7 $os = 'win'; 7 8 $ext = 'bat'; 8 9 } 9 elseif( $ os == 'lin' )10 elseif( $phpos == 'lin' ) 10 11 { 11 12 $os = 'unix'; plugins/sfOpenOfficePlugin/config/ooffice-unix-env.sh
r3891 r3895 4 4 5 5 export LANG=pt_PT.UTF-8 6 export HOME=/var/www/openoffice #must be writable to the root process7 export TEMP=/ var/www/openoffice #must be writable to the root process6 export HOME=/var/www/openoffice 7 export TEMP=/tmp 8 8 export LC_ALL=C 9 9 plugins/sfOpenOfficePlugin/data/tasks/sfPakeOpenOffice.php
r3891 r3895 94 94 95 95 $transformation = realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..') . DIRECTORY_SEPARATOR . 'transformations' 96 . DIRECTORY_SEPARATOR . 'ooffice2php.xsl';96 . DIRECTORY_SEPARATOR . "$extension.xsl"; 97 97 98 98 $xslt->importStyleSheet( DomDocument::load($transformation) ); plugins/sfOpenOfficePlugin/data/transformations/odt.xsl
r3894 r3895 56 56 57 57 58 59 60 61 62 <!-- Charts will fetch data from the cells defined in the action variable with the same name as the object name -->63 <!-- for now that action variable should be something like Sheet1.D9:Sheet1.D9 -->64 <xsl:template match="draw:frame[@draw:name]/draw:object" disable-output-escaping="yes">65 <xsl:copy>66 <xsl:attribute name="draw:notify-on-update-of-ranges"><?php echo $<xsl:value-of select="../@draw:name" disable-output-escaping="yes"/> ?></xsl:attribute>67 <xsl:apply-templates select="@*[not(name()='draw:notify-on-update-of-ranges')]" />68 </xsl:copy>69 </xsl:template>70 71 72 <xsl:template name="code">73 <xsl:param name="node" />74 <xsl:if test="starts-with($node, '<?php') and substring($node, string-length($node)-1, 2)='?>'">75 <?php <xsl:value-of select="substring($node, 6, string-length($node)-7)" disable-output-escaping="yes"/> ?>76 </xsl:if>77 </xsl:template>78 79 58 </xsl:stylesheet>