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

Source for file mime.pdfx.php

Documentation is available at mime.pdfx.php

  1. <?php
  2. /**
  3.  * @version        $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.pdf.php,v 1.2 2009/04/29 14:29:24 wjames5 Exp $
  4.  *
  5.  * @author        xing  <xing@synapse.plus.com>
  6.  * @version        $Revision: 1.2 $
  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_PDFX''mimepdfx' );
  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_pdfx_store',
  29.     'update_function'     => 'mime_pdfx_update',
  30.     'load_function'       => 'mime_pdfx_load',
  31.     'download_function'   => 'mime_default_download',
  32.     'expunge_function'    => 'mime_default_expunge',
  33.     'help_function'       => 'mime_pdfx_help',
  34.     // Brief description of what the plugin does
  35.     'title'               => 'Browsable PDFs with thumbnails',
  36.     'description'         => 'Convert PDFs to flash files that can be browsed online and provides thumbnail images for the galleries and links.',
  37.     // Templates to display the files
  38.     'view_tpl'            => 'bitpackage:liberty/mime/pdfx/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_pdfx.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 raw pdf files
  49.     'mimetypes'           => array(
  50.         '#.*/pdf#i',
  51.     ),
  52. );
  53. $gLibertySystem->registerPluginPLUGIN_MIME_GUID_PDFX$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_pdfx_store&$pStoreRow {
  63.     global $gBitSystem;
  64.  
  65.     // this will set the correct pluign guid, even if we let default handle the store process
  66.     $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_PDFX;
  67.     $pStoreRow['log'array();
  68.  
  69.     // if storing works, we process the image
  70.     if$ret mime_default_store$pStoreRow )) {
  71.         // Dummy for later
  72.     }
  73.     
  74.     if$gBitSystem->getConfig'pdf_thumbnails''y' == 'y' {
  75.         if!mime_pdfx_thumbnail$pStoreRow )) {
  76.             // if it all goes tits up, we'll know why
  77.             $pStoreRow['errors'$pStoreRow['log'];
  78.             $ret FALSE;
  79.         }
  80.     }
  81.     return $ret;
  82. }
  83.  
  84. /**
  85.  * mime_pdf_update update file information in the database if there were changes.
  86.  *
  87.  * @param array $pStoreRow File data needed to update details in the database
  88.  * @access public
  89.  * @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
  90.  */
  91. function mime_pdfx_update&$pStoreRow$pParams NULL {
  92.     global $gThumbSizes$gBitSystem;
  93.  
  94.     $ret TRUE;
  95.  
  96.     // this will set the correct pluign guid, even if we let default handle the store process
  97.     $pStoreRow['attachment_plugin_guid'PLUGIN_MIME_GUID_PDFX;
  98.  
  99.     if$gBitSystem->getConfig'pdf_thumbnails''y' == 'y' {
  100.         if!mime_pdfx_thumbnail$pStoreRow )) {
  101.             // if it all goes tits up, we'll know why
  102.             $pStoreRow['errors'$pStoreRow['log'];
  103.             $ret FALSE;
  104.         }
  105.     }
  106.     return $ret;
  107. }
  108.  
  109. /**
  110.  * Load file data from the database
  111.  *
  112.  * @param array $pFileHash Contains all file information
  113.  * @param array $pPrefs Attachment preferences taken liberty_attachment_prefs
  114.  * @param array $pParams Parameters for loading the plugin - e.g.: might contain values such as thumbnail size from the view page
  115.  * @access public
  116.  * @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
  117.  */
  118. function mime_pdfx_load&$pFileHash&$pPrefs$pParams NULL {
  119.     global $gBitSystem;
  120.     // don't load a mime image if we don't have an image for this file
  121.     if$ret mime_default_load$pFileHash$pPrefs$pParams )) {
  122.         if!empty$ret['source_file')) {
  123.             $source_path dirname$ret['source_file').'/';
  124.             // if the swf file exists, we pass it back that it can be viewed.
  125.             ifis_file$source_path.'pdf.swf' )) {
  126.                 $ret['media_url'storage_path_to_urldirname$ret['source_url').'/pdf.swf' );
  127.             }
  128.         }
  129.     }
  130.     return $ret;
  131. }
  132.  
  133. /**
  134.  * mime_pdfx_thumbnail  Create a jpg thumbnail of the first page of the PDF
  135.  *
  136.  * @param array $pFileHash file details.
  137.  * @param array $pFileHash[upload] should contain a complete hash from $_FILES
  138.  * @access public
  139.  * @return TRUE on success, FALSE on failure
  140.  */
  141. function mime_pdfx_thumbnail$pFileHash {
  142.     global $gBitSystem;
  143.         if$gBitSystem->getConfig'pdf_thumbnails''y' == 'y' {
  144.             $source    STORAGE_PKG_PATH.$pFileHash['upload']['dest_branch'];
  145.  
  146.             if $gBitSystem->isFeatureActive'liberty_jpeg_originals' ) ) {
  147.                 $source .= 'original.jpg';
  148.             else {
  149.                 $source .= $pFileHash['upload']['name'];
  150.             }
  151.             $dest_branch dirname$source );
  152.  
  153.             $thumb_file  "$dest_branch/thumb.jpg";
  154.  
  155.                 $im  new Imagick($source."[0]")// 0-first page, 1-second page
  156.             $im->setImageColorspace(255)// prevent image colors from inverting
  157.             $im->setimageformat("jpeg");
  158.             $im->thumbnailimage(7241024)// width and height
  159.             $im->writeimage($thumb_file);
  160.             $im->clear();
  161.             $im->destroy();
  162.             ifis_file$thumb_file && filesize$thumb_file {
  163.             }
  164.             else ifis_file"$dest_branch/thumb-0.jpg) ) {
  165.                 $thumb_file "$dest_branch/thumb-0.jpg";
  166.             }
  167.             $genHash array(
  168.                 'attachment_id'    => $pFileHash['attachment_id'],
  169.                 'dest_branch'        => $pFileHash['upload']['dest_branch'],
  170.                 'source_file'        => $thumb_file,
  171.                 'type'                => 'image/jpeg',
  172.                 'thumbnail_sizes'    => array'extra-large''large''medium''small''avatar''icon' ),
  173.             );
  174.             ifliberty_generate_thumbnails$genHash )) {
  175. //                $genHash['source_file'] = $genHash['icon_thumb_path'];
  176. //                if( !$panoramaFunc( $genHash )) {
  177. //                    $pStoreRow['errors']['panorama'] = $genHash['error'];
  178. //                }
  179.             }
  180.             $mask "$dest_branch/thumb*.jpg";
  181.                array_map"unlink"glob$mask ) );
  182.         }
  183.     returnempty$pFileHash['log'));
  184. }
  185.  
  186. /**
  187.  * mime_pdf_help
  188.  *
  189.  * @access public
  190.  * @return string 
  191.  */
  192. function mime_pdfx_help({
  193.     return '';
  194. }
  195. ?>

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