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

Source for file mime.flatdefault.php

Documentation is available at mime.flatdefault.php

  1. <?php
  2. /**
  3.  * Mime handler - flat attachments model default
  4.  *
  5.  * As an alternative to storing file attachments in a user based storage tree, this version of mime.default.php
  6.  * provides for a flat filing system based on id. A two level tree is currently provided bassed on a Mod 1000 trimming
  7.  * of the id number for the first level directories. This limits each branch to a maximum of 1000 sub directories but
  8.  * a change the mime_default_branch setting will allow other trimmimg to be implemented.
  9.  *
  10.  * Include
  11.  * define( 'LIBERTY_DEFAULT_MIME_HANDLER', 'mimeflatdefault' );
  12.  * in config_inc.php to activate
  13.  *
  14.  * @package     liberty
  15.  * @subpackage  liberty_mime_handler
  16.  ***/
  17.  
  18. /**
  19.  * setup
  20.  */
  21. global $gLibertySystem;
  22.  
  23. /**
  24.  *  This is the name of the plugin - max char length is 16
  25.  * As a naming convention, the liberty mime handler definition should start with:
  26.  * PLUGIN_MIME_GUID_
  27.  */
  28. define( 'PLUGIN_MIME_GUID_FLATDEFAULT', 'mimeflatdefault' );
  29. define( 'FLAT_STORAGE_NAME', 'attachments' );
  30.  
  31. $pluginParams = array (
  32.     // Set of functions and what they are called in this paricular plugin
  33.     // Use the GUID as your namespace
  34.     'verify_function'    => 'mime_default_verify',
  35.     'store_function'     => 'mime_default_store',
  36.     'update_function'    => 'mime_default_update',
  37.     'load_function'      => 'mime_default_load',
  38.     'branch_function'      => 'mime_default_branch',
  39.     'download_function'  => 'mime_default_download',
  40.     'expunge_function'   => 'mime_default_expunge',
  41.     // Brief description of what the plugin does
  42.     'title'              => 'Default Flat File Handler',
  43.     'description'        => 'This mime handler can handle any file type, creates thumbnails when possible and will make the file available as an attachment under a flat file system.',
  44.     // Templates to display the files
  45.     'upload_tpl'         => 'bitpackage:liberty/mime/default/upload.tpl',
  46.     'view_tpl'           => 'bitpackage:liberty/mime/default/view.tpl',
  47.     'inline_tpl'         => 'bitpackage:liberty/mime/default/inline.tpl',
  48.     'storage_tpl'        => 'bitpackage:liberty/mime/default/storage.tpl',
  49.     'attachment_tpl'     => 'bitpackage:liberty/mime/default/attachment.tpl',
  50.     // This should be the same for all mime plugins
  51.     'plugin_type'        => MIME_PLUGIN,
  52.     // This needs to be specified by plugins that are included by other plugins
  53.     'file_name'          => 'mime.flatdefault.php',
  54.     // Ensure only one mime.default.php version is active and visible
  55.     // Set this to TRUE if you want the plugin active right after installation
  56.     'auto_activate'      => FALSE,
  57.     // Help page on bitweaver.org
  58.     //'help_page'          => 'MimeHelpPage',
  59.  
  60.     // Here you can use a perl regular expression to pick out file extensions you want to handle
  61.     // e.g.: Some image types: '#^image/(jpe?g|gif|png)#i'
  62.     // This plugin will be picked if nothing matches.
  63.     //'mimetypes'          => array( '/.*/' ),
  64. );
  65. $gLibertySystem->registerPlugin( PLUGIN_MIME_GUID_FLATDEFAULT, $pluginParams );
  66.  
  67. /**
  68.  * Sanitise and validate data before it's stored
  69.  *
  70.  * @param array $pStoreRow Hash of data that needs to be stored
  71.  * @param array $pStoreRow['upload'] Hash passed in by $_FILES upload
  72.  * @access public
  73.  * @return TRUE on success, FALSE on failure - $pStoreRow['errors'] will contain reason
  74.  */
  75. if( !function_exists( 'mime_default_verify' )) {
  76.     function mime_default_verify( &$pStoreRow ) {
  77.         global $gBitSystem, $gBitUser;
  78.         $ret = FALSE;
  79.  
  80.         // storage is always owned by the user that uploaded it!
  81.         // er... or at least admin if somehow we have a NULL mUserId - anon uploads maybe?
  82.         $pStoreRow['user_id'] = @BitBase::verifyId( $gBitUser->mUserId ) ? $gBitUser->mUserId : ROOT_USER_ID;
  83.  
  84.         // Bypass p_liberty_attach_attachments for managed uploads - access controlled by fisheye/treasury or other uploader
  85.         // Ignore warning when p_liberty_attach_attachments totally disabled
  86.         // if( $this->hasUserPermission( 'p_liberty_manage_attachments' )) {
  87.             $pStoreRow['no_perm_check'] = true;
  88.         // }
  89.  
  90.         if( !empty( $pStoreRow['upload']['tmp_name'] ) && is_file( $pStoreRow['upload']['tmp_name'] )) {
  91.             // attachment_id is only set when we are updating the file
  92.             if( @BitBase::verifyId( $pStoreRow['upload']['attachment_id'] )) {
  93.                 // if a new file has been uploaded, we need to get some information from the database for the file update
  94.                 $fileInfo = $gBitSystem->mDb->getRow( "
  95.                     SELECT la.`attachment_id`, lf.`file_id`, lf.`file_name`
  96.                     FROM `".BIT_DB_PREFIX."liberty_attachments` la
  97.                     INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON ( lf.`file_id` = la.`foreign_id` )
  98.                     WHERE la.`attachment_id` = ?", array( $pStoreRow['upload']['attachment_id'] ));
  99.                 $pStoreRow = array_merge( $pStoreRow, $fileInfo );
  100.             } else {
  101.                 // try to generate thumbnails for the upload
  102.                 //$pStoreRow['upload']['thumbnail'] = !$gBitSystem->isFeatureActive( 'liberty_offline_thumbnailer' );
  103.                 $pStoreRow['upload']['thumbnail'] = TRUE;
  104.                 // Little cluge - unattached files create an empty ['upload']['attachment_id'] attached ones do not
  105.                 // Really need core liberty to be consistent on identifying these - ideally adding flag for linked files
  106.                 if( isset($pStoreRow['upload']['attachment_id']) ) {
  107.                     $pStoreRow['attachment_id'] = $gBitSystem->mDb->GenID( 'liberty_content_id_seq' );
  108.                 } else {
  109.                     $pStoreRow['attachment_id'] = $pStoreRow['content_id'];
  110.                 }
  111.             }
  112.  
  113.             // Generic values needed by the storing mechanism
  114.             $pStoreRow['upload']['source_file'] = $pStoreRow['upload']['tmp_name'];
  115.  
  116.             // Store all uploaded files in the flat tree storage area
  117.             if( empty( $pStoreRow['upload']['dest_branch'] )) {
  118.                 $pStoreRow['upload']['dest_branch'] = mime_default_branch( $pStoreRow['attachment_id'] );
  119.                 // Use group number to protect disk content - still need to set group of directory!
  120.                 mkdir_p( BIT_ROOT_PATH.$pStoreRow['upload']['dest_branch'], 0770 );
  121.             }
  122.  
  123.             $ret = TRUE;
  124.         } else {
  125.             $pStoreRow['errors']['upload'] = tra( 'There was a problem verifying the uploaded file.' );
  126.         }
  127.  
  128.         return $ret;
  129.     }
  130. }
  131.  
  132. /**
  133.  * When a file is edited
  134.  *
  135.  * @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
  136.  * @access public
  137.  * @return TRUE on success, FALSE on failure - $pStoreRow['errors'] will contain reason
  138.  */
  139. if( !function_exists( 'mime_default_update' )) {
  140.     function mime_default_update( &$pStoreRow ) {
  141.         global $gBitSystem;
  142.  
  143.         // this will reset the uploaded file
  144.         if( BitBase::verifyId( $pStoreRow['attachment_id'] ) && !empty( $pStoreRow['upload'] )) {
  145.             if( empty( $pStoreRow['dest_branch'] )) {
  146.                 $pStoreRow['dest_branch'] = liberty_mime_get_storage_branch( array( 'attachment_id' => $pStoreRow['attachment_id'] ) );
  147.             }
  148.  
  149.             if( !empty( $pStoreRow['dest_branch'] ) && !empty( $pStoreRow['file_name'] ) ) {
  150.                 // First we remove the old file
  151.                 $path = STORAGE_PKG_PATH.$pStoreRow['dest_branch'];
  152.                 $file = $path.$pStoreRow['file_name'];
  153.                 if(( $nuke = LibertyMime::validateStoragePath( $path )) && is_dir( $nuke )) {
  154.                     if( !empty( $pStoreRow['unlink_dir'] )) {
  155.                         @unlink_r( $path );
  156.                         mkdir( $path );
  157.                     } else {
  158.                         @unlink( $file );
  159.                     }
  160.                 }
  161.  
  162.                 // make sure we store the new file in the same place as before
  163.                 $pStoreRow['upload']['dest_branch'] = $pStoreRow['dest_branch'];
  164.  
  165.                 // if we can create new thumbnails for this file, we remove the old ones first
  166.                 $canThumbFunc = liberty_get_function( 'can_thumbnail' );
  167.                 if( !empty( $canThumbFunc ) && $canThumbFunc( $pStoreRow['upload']['type'] )) {
  168.                     liberty_clear_thumbnails( $pStoreRow['upload'] );
  169.                 }
  170.  
  171.                 // Now we process the uploaded file
  172.                 if( $storagePath = liberty_process_upload( $pStoreRow['upload'] )) {
  173.                     $sql = "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_name` = ?, `mime_type` = ?, `file_size` = ?, `user_id` = ? WHERE `file_id` = ?";
  174.                     $gBitSystem->mDb->query( $sql, array( $pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['user_id'], $pStoreRow['file_id'] ));
  175.                 }
  176.  
  177.                 // ensure we have the correct guid in the db
  178.                 if( empty( $pStoreRow['attachment_plugin_guid'] )) {
  179.                     $pStoreRow['attachment_plugin_guid'] = LIBERTY_DEFAULT_MIME_HANDLER;
  180.                 }
  181.  
  182.                 $gBitSystem->mDb->associateUpdate(
  183.                     BIT_DB_PREFIX."liberty_attachments",
  184.                     array( 'attachment_plugin_guid' => $pStoreRow['attachment_plugin_guid'] ),
  185.                     array( 'attachment_id' => $pStoreRow['attachment_id'] )
  186.                 );
  187.             }
  188.         }
  189.         return TRUE;
  190.     }
  191. }
  192.  
  193. /**
  194.  * Store the data in the database
  195.  *
  196.  * @param array $pStoreRow File data needed to store details in the database - sanitised and generated in the verify function
  197.  * @access public
  198.  * @return TRUE on success, FALSE on failure - $pStoreRow['errors'] will contain reason
  199.  */
  200. if( !function_exists( 'mime_default_store' )) {
  201.     function mime_default_store( &$pStoreRow ) {
  202.         global $gBitSystem, $gLibertySystem;
  203.         $ret = FALSE;
  204.         // take care of the uploaded file and insert it into the liberty_files and liberty_attachments tables
  205.         if( $storagePath = liberty_process_upload( $pStoreRow['upload'], empty( $pStoreRow['upload']['copy_file'] ))) {
  206.             // add row to liberty_files
  207.             $storeHash = array(
  208.                 "file_name" => $pStoreRow['upload']['name'],
  209.                 "file_id"   => $pStoreRow['attachment_id'],
  210.                 "mime_type" => $pStoreRow['upload']['type'],
  211.                 "file_size" => $pStoreRow['upload']['size'],
  212.                 "user_id"   => $pStoreRow['user_id'],
  213.             );
  214.             if ( !$storeHash['file_size'] ) { $storeHash['file_size'] = 0; }
  215.  
  216.             $gBitSystem->mDb->associateInsert( BIT_DB_PREFIX."liberty_files", $storeHash );
  217.  
  218.             // add the data into liberty_attachments to make this file available as attachment
  219.             $storeHash = array(
  220.                 "attachment_id"          => $pStoreRow['attachment_id'],
  221.                 "content_id"             => $pStoreRow['content_id'],
  222.                 "attachment_plugin_guid" => !empty( $pStoreRow['attachment_plugin_guid'] ) ? $pStoreRow['attachment_plugin_guid'] : PLUGIN_MIME_GUID_FLATDEFAULT,
  223.                 "foreign_id"             => $pStoreRow['attachment_id'],
  224.                 "user_id"                => $pStoreRow['user_id'],
  225.             );
  226.             $gBitSystem->mDb->associateInsert( BIT_DB_PREFIX."liberty_attachments", $storeHash );
  227.  
  228.             $ret = TRUE;
  229.         } else {
  230.             $pStoreRow['errors']['liberty_process'] = "There was a problem processing the file.";
  231.         }
  232.         return $ret;
  233.     }
  234. }
  235.  
  236. /**
  237.  * Load file data from the database
  238.  *
  239.  * @param array $pFileHash contains all file information
  240.  * @access public
  241.  * @return TRUE on success, FALSE on failure - ['errors'] will contain reason for failure
  242.  */
  243. if( !function_exists( 'mime_default_load' )) {
  244.     function mime_default_load( $pFileHash, &$pPrefs ) {
  245.         global $gBitSystem, $gLibertySystem;
  246.         $ret = FALSE;
  247.     if( @BitBase::verifyId( $pFileHash['attachment_id'] )) {
  248.             $query = "
  249.                 SELECT *
  250.                 FROM `".BIT_DB_PREFIX."liberty_attachments` la
  251.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( la.`foreign_id` = lf.`file_id` )
  252.                 WHERE la.`attachment_id`=?";
  253.             if( $row = $gBitSystem->mDb->getRow( $query, array( $pFileHash['attachment_id'] ))) {
  254.                 $ret = array_merge( $pFileHash, $row );
  255.                 $storageName = basename( $row['file_name'] );
  256.                 // compatibility with _FILES hash
  257.                 $row['name'] = $storageName;
  258.                 $row['type'] = $row['mime_type'];
  259.                 $storageBranch = liberty_mime_get_storage_branch( array( 'attachment_id' => $row['attachment_id'] ) ).$storageName;
  260.                 // this will fetch the correct thumbnails
  261.                 $thumbHash['source_file'] = STORAGE_PKG_PATH.$storageBranch;
  262.                 $row['source_file'] = STORAGE_PKG_PATH.$storageBranch;
  263.                 $canThumbFunc = liberty_get_function( 'can_thumbnail' );
  264.                 if( $canThumbFunc && $canThumbFunc( $row['mime_type'] )) {
  265.                     $thumbHash['default_image'] = LIBERTY_PKG_URL.'icons/generating_thumbnails.png';
  266.                 }
  267.                 $ret['thumbnail_url'] = liberty_fetch_thumbnails( $thumbHash );
  268.                 // indicate that this is a mime thumbnail
  269.                 if( !empty( $ret['thumbnail_url']['medium'] ) && strpos( $ret['thumbnail_url']['medium'], '/mime/' )) {
  270.                     $ret['thumbnail_is_mime'] = TRUE;
  271.                 }
  272.  
  273.                 // pretty URLs
  274.                 if( $gBitSystem->isFeatureActive( "pretty_urls" ) || $gBitSystem->isFeatureActive( "pretty_urls_extended" )) {
  275.                     $ret['display_url'] = LIBERTY_PKG_URL."view/file/".$row['attachment_id'];
  276.                 } else {
  277.                     $ret['display_url'] = LIBERTY_PKG_URL."view_file.php?attachment_id=".$row['attachment_id'];
  278.                 }
  279.  
  280.                 // legacy table data was named storage path and included a partial path. strip out any path just in case
  281.                 $ret['file_name']    = $storageName;
  282.                 $ret['preferences'] = $pPrefs;
  283.  
  284.                 // some stuff is only available if we have a source file
  285.                 //    make sure to check for these when you use them. frequently the original might not be available
  286.                 //    e.g.: video files are large and the original might be deleted after conversion
  287.                 if( is_file( STORAGE_PKG_PATH.$storageBranch )) {
  288.                     $ret['source_file']   = STORAGE_PKG_PATH.$storageBranch;
  289.                     $ret['source_url']    = STORAGE_PKG_URL.$storageBranch;
  290.                     $ret['last_modified'] = filemtime( $ret['source_file'] );
  291.                     if( $gBitSystem->isFeatureActive( "pretty_urls" ) || $gBitSystem->isFeatureActive( "pretty_urls_extended" )) {
  292.                         $ret['download_url'] = LIBERTY_PKG_URL."download/file/".$row['attachment_id'];
  293.                     } else {
  294.                         $ret['download_url'] = LIBERTY_PKG_URL."download_file.php?attachment_id=".$row['attachment_id'];
  295.                     }
  296.                 }
  297.  
  298.                 // add a description of how to insert this file into a wiki page
  299.                 if( $gLibertySystem->isPluginActive( 'dataattachment' )) {
  300.                     $ret['wiki_plugin_link'] = "{image id=".$row['attachment_id']."}";
  301.                 }
  302.  
  303.                 // additionally we'll add this to distinguish between old plugins and new ones
  304.                 // TODO: this should hopefully not be necessary for too long
  305.                 $ret['is_mime'] = TRUE;
  306.             }
  307.         }
  308.         return $ret;
  309.     }
  310. }
  311.  
  312. /**
  313.  * Takes care of the entire download process. Make sure it doesn't die at the end.
  314.  * in this functioin it would be possible to add download resume possibilites and the like
  315.  *
  316.  * @param array $pFileHash Basically the same has as returned by the load function
  317.  * @access public
  318.  * @return TRUE on success, FALSE on failure - $pParamHash['errors'] will contain reason for failure
  319.  */
  320. if( !function_exists( 'mime_default_download' )) {
  321.     function mime_default_download( &$pFileHash ) {
  322.         global $gBitSystem;
  323.         $ret = FALSE;
  324.  
  325.         // Check to see if the file actually exists
  326.         if( !empty( $pFileHash['source_file'] ) && is_readable( $pFileHash['source_file'] )) {
  327.             // if we have PEAR HTTP/Download installed, we make use of it since it allows download resume and download manager access
  328.             // read the docs if you want to enable download throttling and the like
  329.             if( @include_once( 'HTTP/Download.php' )) {
  330.                 $dl = new HTTP_Download();
  331.                 $dl->setLastModified( $pFileHash['last_modified'] );
  332.                 $dl->setFile( $pFileHash['source_file'] );
  333.                 //$dl->setContentDisposition( HTTP_DOWNLOAD_INLINE, $pFileHash['file_name'] );
  334.                 $dl->setContentDisposition( HTTP_DOWNLOAD_ATTACHMENT, $pFileHash['file_name'] );
  335.                 $dl->setContentType( $pFileHash['mime_type'] );
  336.                 $res = $dl->send();
  337.  
  338.                 if( PEAR::isError( $res )) {
  339.                     $gBitSystem->fatalError( $res->getMessage() );
  340.                 } else {
  341.                     $ret = TRUE;
  342.                 }
  343.             } else {
  344.                 // make sure we close off obzip compression if it's on
  345.                 if( $gBitSystem->isFeatureActive( 'site_output_obzip' )) {
  346.                     @ob_end_clean();
  347.                 }
  348.  
  349.                 // this will get the browser to open the download dialogue - even when the
  350.                 // browser could deal with the content type - not perfect, but works
  351.                 if( $gBitSystem->isFeatureActive( 'mime_force_download' )) {
  352.                     $pFileHash['mime_type'] = "application/force-download";
  353.                 }
  354.  
  355.                 header( "Cache Control: " );
  356.                 header( "Accept-Ranges: bytes" );
  357.                 header( "Content-type: ".$pFileHash['mime_type'] );
  358.                 header( "Content-Disposition: attachment; filename=".$pFileHash['file_name'] );
  359.                 header( "Last-Modified: ".gmdate( "D, d M Y H:i:s", $pFileHash['last_modified'] )." GMT", true, 200 );
  360.                 header( "Content-Length: ".filesize( $pFileHash['source_file'] ));
  361.                 header( "Content-Transfer-Encoding: binary" );
  362.                 header( "Connection: close" );
  363.  
  364.                 readfile( $pFileHash['source_file'] );
  365.                 $ret = TRUE;
  366.                 die;
  367.             }
  368.         } else {
  369.             $pFileHash['errors']['no_file'] = tra( 'No matching file found.' );
  370.         }
  371.         return $ret;
  372.     }
  373. }
  374.  
  375. /**
  376.  * Nuke data in tables when content is removed
  377.  *
  378.  * @param integer $pAttachmentId The id of the attachment to delete
  379.  * @access public
  380.  * @return TRUE on success, FALSE on failure
  381.  */
  382. if( !function_exists( 'mime_default_expunge' )) {
  383.     function mime_default_expunge( $pAttachmentId ) {
  384.         global $gBitSystem, $gBitUser;
  385.         $ret = FALSE;
  386.         if( @BitBase::verifyId( $pAttachmentId )) {
  387.             if( $fileHash = LibertyMime::loadAttachment( $pAttachmentId )) {
  388.                 if( $gBitUser->isAdmin() || $gBitUser->mUserId == $fileHash['user_id'] && isset( $fileHash['source_file'] ) && !empty( $fileHash['source_file'] )) {
  389.                     // make sure this is a valid storage directory before removing it
  390.                     if( preg_match( "#^".realpath( STORAGE_PKG_PATH )."/attachments/\d+/\d+/#", $fileHash['source_file'] ) && is_file( $fileHash['source_file'] )) {
  391.                         unlink_r( dirname( $fileHash['source_file'] ));
  392.                     }
  393.                     $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?";
  394.                     $gBitSystem->mDb->query( $query, array( $fileHash['foreign_id'] ));
  395.                     $ret = TRUE;
  396.                 }
  397.             }
  398.         }
  399.         return $ret;
  400.     }
  401. }
  402.  
  403. /**
  404.  * Generate branch from Id
  405.  *
  406.  * @param integer $pAttachmentId The id of the attachment to access
  407.  * @access public
  408.  * @return string containing path to storage location for attachment
  409.  */
  410. if( !function_exists( 'mime_default_branch' )) {
  411.     function mime_default_branch( $pAttachmentId ) {
  412.         $ret = FALSE;
  413.         if( @BitBase::verifyId( $pAttachmentId ) ) {
  414.             $ret = FLAT_STORAGE_NAME.'/'.($pAttachmentId % 1000).'/'.$pAttachmentId.'/';
  415.         }
  416.         return $ret;
  417.     }
  418. }
  419.  
  420. /**
  421.  * liberty_mime_get_storage_branch - get url to store files for the feature site_upload_dir. It creates a calculable hierarchy of directories
  422.  *
  423.  * @access public
  424.  * @author Lester Caine<lester@lsces.co.uk>
  425.  * @param $pParamHash key=>value pairs to determine path. Possible keys in descending directory depth are: use the 'common' branch if null, 'package' - any desired directory below the StoragePath. this will be created if it doesn't exist, 'sub_dir' -  the sub-directory in the package organization directory, this is often a primary id such as attachment_id
  426.  * @return string full path on local filsystem to store files.
  427.  */
  428. if( !function_exists( 'liberty_mime_get_storage_branch' )) {
  429.     function liberty_mime_get_storage_branch( $pParamHash ) { // $pSubDir = NULL, $pUserId = NULL, $pPackage = ACTIVE_PACKAGE, $pPermissions = 0755, $pCreateDir = true ) {
  430.         // *PRIVATE FUNCTION. GO AWAY! DO NOT CALL DIRECTLY!!!
  431.         global $gBitSystem;
  432.         $pathParts = array();
  433.  
  434.         if( $pAttachmentId = BitBase::getParameter( $pParamHash, 'attachment_id' ) ) {
  435.             $pathParts[] = 'attachments';
  436.             $pathParts[] = (int)($pAttachmentId % 1000);
  437.             $pathParts[] = $pAttachmentId;
  438. // Added in fisheye override
  439.         } else {
  440.             $pathParts[] = 'common';
  441.         }
  442.  
  443.         if( $pPackage = BitBase::getParameter( $pParamHash, 'package' ) ) {
  444.             $pathParts[] = $pPackage;
  445.         }
  446.  
  447.         $fullPath = implode( $pathParts, '/' ).'/';
  448.         if( BitBase::getParameter( $pParamHash, 'create_dir', TRUE ) ){
  449.             if( !file_exists( STORAGE_PKG_PATH.$fullPath ) ) {
  450.                 mkdir_p( STORAGE_PKG_PATH.$fullPath );
  451.             }
  452.         }
  453.         return $fullPath;
  454.     }
  455. }
  456.  
  457. if( !function_exists( 'liberty_mime_get_source_url' )) {
  458.     function liberty_mime_get_source_url( $pParamHash ) {
  459.         if( empty( $pParamHash['package'] ) ) {
  460.             $pParamHash['package'] = liberty_mime_get_storage_sub_dir_name( array( 'type' => BitBase::getParameter( $pParamHash, 'mime_type' ), 'name' => BitBase::getParameter( $pParamHash, 'file_name' ) ) );
  461.         }
  462.         if( empty( $pParamHash['sub_dir'] ) ) {
  463.             $pParamHash['sub_dir'] = BitBase::getParameter( $pParamHash, 'attachment_id' );
  464.         }
  465.         return STORAGE_PKG_URL.liberty_mime_get_storage_branch( $pParamHash ).basename( BitBase::getParameter( $pParamHash, 'file_name' ) );
  466.     }
  467. }
  468.  
  469. if( !function_exists( 'liberty_mime_get_source_file' )) {
  470.     function liberty_mime_get_source_file( $pParamHash ) {
  471.         if( empty( $pParamHash['package'] ) ) {
  472.             $pParamHash['package'] = liberty_mime_get_storage_sub_dir_name( array( 'type' => BitBase::getParameter( $pParamHash, 'mime_type' ), 'name' => BitBase::getParameter( $pParamHash, 'file_name' ) ) );
  473.         }
  474.         if( empty( $pParamHash['sub_dir'] ) ) {
  475.             $pParamHash['sub_dir'] = BitBase::getParameter( $pParamHash, 'attachment_id' );
  476.         }
  477.         return STORAGE_PKG_PATH.liberty_mime_get_storage_branch( $pParamHash ).basename( BitBase::getParameter( $pParamHash, 'file_name' ) );
  478.     }
  479. }
  480.  
  481.  
  482. ?>

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