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

Source for file mime.pdf.php

Documentation is available at mime.pdf.php

  1. <?php
  2. /**
  3.  * @version        $Header$
  4.  *
  5.  * @author        xing  <xing@synapse.plus.com>
  6.  * @version        $Revision$
  7.  *  created        Thursday May 08, 2008
  8.  * @package        liberty
  9.  * @subpackage    liberty_mime_handler
  10.  ***/
  11.  
  12. /**
  13.  * setup
  14.  */
  15. global $gLibertySystem;
  16.  
  17. /**
  18.  *  This is the name of the plugin - max char length is 16
  19.  * As a naming convention, the liberty mime handler definition should start with:
  20.  * PLUGIN_MIME_GUID_
  21.  */
  22. define'PLUGIN_MIME_GUID_PDF''mimepdf' );
  23.  
  24. $pluginParams array (
  25.     // Set of functions and what they are called in this paricular plugin
  26.     // Use the GUID as your namespace
  27.     'verify_function'     => 'mime_default_verify',
  28.     'store_function'      => 'mime_pdf_store',
  29.     'update_function'     => 'mime_pdf_update',
  30.     'load_function'       => 'mime_pdf_load',
  31.     'download_function'   => 'mime_default_download',
  32.     'expunge_function'    => 'mime_default_expunge',
  33.     //'help_function'       => 'mime_pdf_help',
  34.     // Brief description of what the plugin does
  35.     'title'               => 'Browsable PDFs',
  36.     'description'         => 'Convert PDFs to flash files that can be browsed online.',
  37.     // Templates to display the files
  38.     'view_tpl'            => 'bitpackage:liberty/mime/pdf/view.tpl',
  39.     //'attachment_tpl'      => 'bitpackage:liberty/mime/image/attachment.tpl',
  40.     // url to page with options for this plugin
  41.     'plugin_settings_url' => LIBERTY_PKG_URL.'admin/plugins/mime_pdf.php',
  42.     // This should be the same for all mime plugins
  43.     'plugin_type'         => MIME_PLUGIN,
  44.     // Set this to TRUE if you want the plugin active right after installation
  45.     'auto_activate'       => FALSE,
  46.     // Help page on bitweaver.org
  47.     //'help_page'           => 'LibertyMime+Image+Plugin',
  48.     // this should pick up all image
  49.     'mimetypes'           => array(
  50.         '#.*/pdf#i',
  51.     ),
  52. );
  53. $gLibertySystem->registerPluginPLUGIN_MIME_GUID_PDF$pluginParams );
  54.  
  55. /**
  56.  * Store the data in the database
  57.  *
  58.  * @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
  59.  * @access public
  60.  * @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
  61.  */
  62. function mime_pdf_store&$pStoreRow {
  63.     // this will set the correct pluign guid, even if we let default handle the store process
  64.     $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_PDF;
  65.     $pStoreRow['log'array();
  66.  
  67.     // if storing works, we process the image
  68.     if$ret mime_default_store$pStoreRow )) {
  69.         if!mime_pdf_convert_pdf2swf$pStoreRow )) {
  70.             // if it all goes tits up, we'll know why
  71.             $pStoreRow['errors'$pStoreRow['log'];
  72.             $ret FALSE;
  73.         }
  74.     }
  75.     return $ret;
  76. }
  77.  
  78. /**
  79.  * mime_pdf_update update file information in the database if there were changes.
  80.  *
  81.  * @param array $pStoreRow File data needed to update details in the database
  82.  * @access public
  83.  * @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
  84.  */
  85. function mime_pdf_update&$pStoreRow$pParams NULL {
  86.     global $gThumbSizes$gBitSystem;
  87.  
  88.     $ret TRUE;
  89.  
  90.     // this will set the correct pluign guid, even if we let default handle the store process
  91.     $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_PDF;
  92.  
  93.     // if storing works, we process the image
  94.     if!empty$pStoreRow['upload'&& $ret mime_default_update$pStoreRow )) {
  95.     }
  96.  
  97.     return $ret;
  98. }
  99.  
  100. /**
  101.  * Load file data from the database
  102.  *
  103.  * @param array $pFileHash Contains all file information
  104.  * @param array $pPrefs Attachment preferences taken liberty_attachment_prefs
  105.  * @param array $pParams Parameters for loading the plugin - e.g.: might contain values such as thumbnail size from the view page
  106.  * @access public
  107.  * @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
  108.  */
  109. function mime_pdf_load&$pFileHash&$pPrefs$pParams NULL {
  110.     global $gBitSystem;
  111.     // don't load a mime image if we don't have an image for this file
  112.     if$ret mime_default_load$pFileHash$pPrefs$pParams )) {
  113.         if!empty$ret['source_file')) {
  114.             $source_path dirname$ret['source_file').'/';
  115.             // if the swf file exists, we pass it back that it can be viewed.
  116.             ifis_file$source_path.'pdf.swf' )) {
  117.                 $ret['media_url'storage_path_to_urldirname$ret['source_url').'/pdf.swf' );
  118.             }
  119.         }
  120.     }
  121.     return $ret;
  122. }
  123.  
  124. /**
  125.  * mime_pdf_convert_pdf2swf Convert a PDF to a SWF video
  126.  *
  127.  * @param array $pFileHash file details.
  128.  * @param array $pFileHash[upload] should contain a complete hash from $_FILES
  129.  * @access public
  130.  * @return TRUE on success, FALSE on failure
  131.  */
  132. function mime_pdf_convert_pdf2swf$pFileHash {
  133.     global $gBitSystem;
  134.     if!empty$pFileHash['upload'&& @BitBase::verifyId$pFileHash['attachment_id')) {
  135.         // get file paths
  136.         $pdf2swf    trim$gBitSystem->getConfig'swf2pdf_path'shell_exec'which pdf2swf' )));
  137.         $swfcombine trim$gBitSystem->getConfig'swfcombine_path'shell_exec'which swfcombine' )));
  138.  
  139.         ifis_executable$pdf2swf && is_executable$swfcombine )) {
  140.             $source    STORAGE_PKG_PATH.$pFileHash['upload']['dest_branch'];
  141.             if $gBitSystem->isFeatureActive'liberty_jpeg_originals' ) ) {
  142.                 $source .= 'original.jpg';
  143.             else {
  144.                 $source .= $pFileHash['upload']['name'];
  145.             }
  146.             $destPath dirname$source );
  147.  
  148.             $tmp_file  "$destPath/tmp.swf";
  149.             $swf_file  "$destPath/pdf.swf";
  150.  
  151.             $pdfviewer UTIL_PKG_PATH."javascript/pdfviewer/fdviewer.swf";
  152.             $swfloader UTIL_PKG_PATH."javascript/pdfviewer/loader.swf";
  153.  
  154.             $pdf2swfcommand "$pdf2swf -s insertstop -s jpegquality=".$gBitSystem->getConfig'liberty_thumbnail_quality'85 )." '$source' -o '$tmp_file'";
  155.             $combinecommand "$swfcombine '$pdfviewer' loader='$swfloader' '#1'='$tmp_file' -o '$swf_file'";
  156.  
  157.             shell_exec$pdf2swfcommand );
  158.             ifis_file$tmp_file && filesize$tmp_file {
  159.                 shell_exec$combinecommand );
  160.                 if!is_file$swf_file || filesize$swf_file == {
  161.                     // combination went wrong. remove swf file
  162.                     $pFileHash['log']['swfcombine'"There was a problem combining the PDF SWF with the viewer.";
  163.                     @unlink$swf_file );
  164.                 }
  165.             else {
  166.                 $pFileHash['log']['pdf2swf'"There was a problem converting the PDF to SWF.";
  167.             }
  168.  
  169.             // remove temp file
  170.             @unlink$tmp_file );
  171.         }
  172.     }
  173.  
  174.     returnempty$pFileHash['log'));
  175. }
  176.  
  177. /**
  178.  * mime_pdf_help
  179.  *
  180.  * @access public
  181.  * @return string 
  182.  */
  183. function mime_pdf_help({
  184.     return '';
  185. }
  186. ?>

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