Source for file mime.pdfx.php
Documentation is available at mime.pdfx.php
* @version $Header: /cvsroot/bitweaver/_bit_liberty/plugins/mime.pdf.php,v 1.2 2009/04/29 14:29:24 wjames5 Exp $
* @author xing <xing@synapse.plus.com>
* @version $Revision: 1.2 $
* created Thursday May 08, 2008
* @subpackage liberty_mime_handler
* This is the name of the plugin - max char length is 16
* As a naming convention, the liberty mime handler definition should start with:
define( 'PLUGIN_MIME_GUID_PDFX', 'mimepdfx' );
// Set of functions and what they are called in this paricular plugin
// Use the GUID as your namespace
'verify_function' => 'mime_default_verify',
'store_function' => 'mime_pdfx_store',
'update_function' => 'mime_pdfx_update',
'load_function' => 'mime_pdfx_load',
'download_function' => 'mime_default_download',
'expunge_function' => 'mime_default_expunge',
'help_function' => 'mime_pdfx_help',
// Brief description of what the plugin does
'title' => 'Browsable PDFs with thumbnails',
'description' => 'Convert PDFs to flash files that can be browsed online and provides thumbnail images for the galleries and links.',
// Templates to display the files
'view_tpl' => 'bitpackage:liberty/mime/pdfx/view.tpl',
//'attachment_tpl' => 'bitpackage:liberty/mime/image/attachment.tpl',
// url to page with options for this plugin
// This should be the same for all mime plugins
// Set this to TRUE if you want the plugin active right after installation
'auto_activate' => FALSE,
// Help page on bitweaver.org
//'help_page' => 'LibertyMime+Image+Plugin',
// this should pick up all raw pdf files
* Store the data in the database
* @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
* @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
// this will set the correct pluign guid, even if we let default handle the store process
$pStoreRow['log'] = array();
// if storing works, we process the image
if( $gBitSystem->getConfig( 'pdf_thumbnails', 'y' ) == 'y' ) {
// if it all goes tits up, we'll know why
$pStoreRow['errors'] = $pStoreRow['log'];
* mime_pdf_update update file information in the database if there were changes.
* @param array $pStoreRow File data needed to update details in the database
* @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
global $gThumbSizes, $gBitSystem;
// this will set the correct pluign guid, even if we let default handle the store process
if( $gBitSystem->getConfig( 'pdf_thumbnails', 'y' ) == 'y' ) {
// if it all goes tits up, we'll know why
$pStoreRow['errors'] = $pStoreRow['log'];
* Load file data from the database
* @param array $pFileHash Contains all file information
* @param array $pPrefs Attachment preferences taken liberty_attachment_prefs
* @param array $pParams Parameters for loading the plugin - e.g.: might contain values such as thumbnail size from the view page
* @return TRUE on success, FALSE on failure - $pStoreRow[errors] will contain reason
// don't load a mime image if we don't have an image for this file
if( !empty( $ret['source_file'] )) {
$source_path = dirname( $ret['source_file'] ). '/';
// if the swf file exists, we pass it back that it can be viewed.
if( is_file( $source_path. 'pdf.swf' )) {
* mime_pdfx_thumbnail Create a jpg thumbnail of the first page of the PDF
* @param array $pFileHash file details.
* @param array $pFileHash[upload] should contain a complete hash from $_FILES
* @return TRUE on success, FALSE on failure
if( $gBitSystem->getConfig( 'pdf_thumbnails', 'y' ) == 'y' ) {
$source .= 'original.jpg';
$source .= $pFileHash['upload']['name'];
$thumb_file = "$dest_branch/thumb.jpg";
$im = new Imagick($source. "[0]"); // 0-first page, 1-second page
$im->setImageColorspace(255); // prevent image colors from inverting
$im->setimageformat("jpeg");
$im->thumbnailimage(724, 1024); // width and height
$im->writeimage($thumb_file);
else if( is_file( "$dest_branch/thumb-0.jpg" ) ) {
$thumb_file = "$dest_branch/thumb-0.jpg";
'attachment_id' => $pFileHash['attachment_id'],
'dest_branch' => $pFileHash['upload']['dest_branch'],
'source_file' => $thumb_file,
'thumbnail_sizes' => array( 'extra-large', 'large', 'medium', 'small', 'avatar', 'icon' ),
// $genHash['source_file'] = $genHash['icon_thumb_path'];
// if( !$panoramaFunc( $genHash )) {
// $pStoreRow['errors']['panorama'] = $genHash['error'];
$mask = "$dest_branch/thumb*.jpg";
return( empty( $pFileHash['log'] ));
|