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

Source for file storage.bitfile.php

Documentation is available at storage.bitfile.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  * @package  liberty
  5.  * @subpackage plugins_storage
  6.  */
  7. global $gLibertySystem$gBitSystem$gBitSmarty$gBitThemes;
  8.  
  9. /**
  10.  * definitions
  11.  */
  12. define'PLUGIN_GUID_BIT_FILES''bitfile' );
  13.  
  14. $pluginParams array (
  15.     'store_function'     => 'bit_files_store',
  16.     'verify_function'    => 'bit_files_verify',
  17.     'load_function'      => 'bit_files_load',
  18.     'expunge_function'   => 'bit_files_expunge',
  19.     'description'        => 'Always load by default, disable to prevent Direct File Upload To Server',
  20.     'plugin_type'        => STORAGE_PLUGIN,
  21.     'auto_activate'      => FALSE,
  22.     'edit_label'         => 'Upload File',
  23.     'primary_edit_field' => '<input type="file" name="primary_attachment" size="40" />',
  24.     'edit_field'         => '<input type="file" name="upload" size="40" />',
  25.     'edit_help'          => 'After selecting the file you want to upload, please return to the edit area and click the save button.'
  26. );
  27.  
  28. ifisset$gBitSystem )) {
  29.     if ($gBitSystem->getConfig("liberty_attachment_style"== "multiple"{
  30.         $pluginParams['edit_label''Upload File(s)';
  31.         $pluginParams['edit_help'=  'The file(s) will be uploaded to your personal storage area.<br />After selecting the file(s) you want to upload, please return to the edit area and click the save button.';
  32.         $pluginParams['edit_field''<div id="upload_div"></div><input type="file" name="upload" size="40" id="uploads" />'.
  33.             '<!-- Multiselect javascript. -->'.
  34.             '<script type="text/javascript" src="'.UTIL_PKG_URL.'javascript/multifile.js"></script>'.
  35.             '<script type="text/javascript">'.
  36.                 'var upload_files = document.getElementById( \'upload_div\' );'.
  37.                 'var upload_element = document.getElementById( \'uploads\' );'.
  38.                 'var multi_selector = new MultiSelector( upload_files, '.$gBitSystem->getConfig('liberty_max_multiple_attachments'10).' );'.
  39.                 'multi_selector.addNamedElement( upload_element , \'uploads\');'.
  40.             '</script>';
  41.         $gBitSmarty->assign'loadMultiFile'TRUE );
  42.     elseif$gBitSystem->getConfig'liberty_attachment_style' == "ajax" {
  43.         $pluginParams['edit_help_new'$pluginParams['edit_help'];
  44.         $pluginParams['edit_field_new'$pluginParams['edit_field'];
  45.         $pluginParams['edit_help'=  'The file(s) will be uploaded to your personal storage area.<br />After selecting the file you want to upload an attachment ID will be displayed for you to use in your content.';
  46.         $pluginParams['edit_field''<input type="file" name="upload" size="40" id="upload" onchange="javascript:LibertyAttachment.uploader(this, \'{$smarty.const.LIBERTY_PKG_URL}attachment_uploader.php\',\'{tr}Please wait for the current upload to finish.{/tr}\', \'liberty_upload_frame\', \'editpageform\');" />'.
  47.             '{include file="bitpackage:liberty/attachment_uploader_inc.tpl"}';
  48.     }
  49. }
  50. //$gLibertySystem->registerPlugin( STORAGE_TYPE_BIT_FILES, $pluginParams );
  51. $gLibertySystem->registerPluginPLUGIN_GUID_BIT_FILES$pluginParams );
  52.  
  53.  
  54. function bit_files_verify&$pStoreRow {
  55.     $pStoreRow['plugin_guid'PLUGIN_GUID_BIT_FILES;
  56.     $pStoreRow['foreign_id'NULL;
  57.     ifstrlen$pStoreRow['upload']['name'200 {
  58.         $pStoreRow['upload']['name'substr$pStoreRow['upload']['name']0195 ).'.'.substr$pStoreRow['upload']['name']strrpos$pStoreRow['upload']['name']'.' ) );
  59.     }
  60.     $pStoreRow['dest_base_name'substr$pStoreRow['upload']['name']0strrpos$pStoreRow['upload']['name']'.' ) );
  61.     iffunction_exists'transliterate' ) ) {
  62. //        $pStoreRow['dest_base_name'] = transliterate( $pStoreRow['dest_base_name'], array('han_transliterate', 'diacritical_remove'), 'utf-8', 'utf-8' );
  63.     }
  64.     $pStoreRow['source_file'$pStoreRow['upload']['tmp_name'];
  65.  
  66.     returnTRUE );
  67. }
  68.  
  69. function bit_files_store&$pStoreRow {
  70.     global $gBitSystem$gBitUser;
  71.     $ret NULL;
  72.     // we have been given an attachment_id but no foreign_id. we will make a last attempt to see if this is an update or an insert
  73.     if@BitBase::verifyId$pStoreRow['attachment_id'&& !@BitBase::verifyId$pStoreRow['foreign_id')) {
  74.         $pStoreRow['foreign_id'$gBitSystem->mDb->getOne"SELECT `foreign_id` FROM `".BIT_DB_PREFIX."liberty_attachments` WHERE `attachment_id` = ?"array$pStoreRow['attachment_id'));
  75.     }
  76.  
  77.     if@BitBase::verifyId$pStoreRow['foreign_id') ) {
  78.         $sql "UPDATE `".BIT_DB_PREFIX."liberty_files` SET `file_name`=?, `mime_type`=?, `file_size`=? WHERE `file_id` = ?";
  79.         $gBitSystem->mDb->query$sqlarray$pStoreRow['upload']['name']$pStoreRow['upload']['type']$pStoreRow['upload']['size']$pStoreRow['foreign_id') );
  80.     else {
  81.         $pStoreRow['foreign_id'$gBitSystem->mDb->GenID'liberty_files_id_seq' );
  82.         $sql "INSERT INTO `".BIT_DB_PREFIX."liberty_files` ( `file_name`, `file_id`, `mime_type`, `file_size`, `user_id` ) VALUES ( ?, ?, ?, ?, ? )";
  83.         $userId !empty$pStoreRow['upload']['user_id'$pStoreRow['upload']['user_id'$gBitUser->mUserId;
  84.         $gBitSystem->mDb->query($sqlarray$pStoreRow['upload']['name']$pStoreRow['foreign_id'],  $pStoreRow['upload']['type'],  $pStoreRow['upload']['size']$userId ) );
  85.     }
  86.     return $ret;
  87. }
  88.  
  89. function bit_files_load$pRow {
  90. // this fuction broken, will fix soon - spiderr
  91. // I think its fixed now - no promises though! - drewslater
  92.     global $gBitSystem$gLibertySystem;
  93.     $ret array();
  94.     if!empty$pRow['foreign_id'&& is_numeric$pRow['foreign_id')) {
  95.         $query "
  96.             SELECT *
  97.             FROM `".BIT_DB_PREFIX."liberty_attachments` la
  98.                 INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON (lf.`file_id` = la.`foreign_id`)
  99.             WHERE la.`foreign_id` = ? AND `attachment_plugin_guid` = ?";
  100.         if$ret $gBitSystem->mDb->getRow$queryarray$pRow['foreign_id']PLUGIN_GUID_BIT_FILES ))) {
  101.             $ret['file_name'basename$ret['file_name');
  102.             $ret['source_file'liberty_mime_get_source_file$ret );
  103.             $canThumbFunc liberty_get_function'can_thumbnail' );
  104.             if$canThumbFunc$ret['mime_type')) {
  105.                 $thumbHash['default_image'LIBERTY_PKG_URL.'icons/generating_thumbnails.png';
  106.             }
  107.             $ret['source_url'liberty_mime_get_source_url$ret );
  108.             $ret['thumbnail_url'liberty_fetch_thumbnails$ret );
  109.             $ret['wiki_plugin_link'"{attachment id=".$ret['attachment_id']."}";
  110.         }
  111.     }
  112.     return$ret );
  113. }
  114.  
  115. function bit_files_expunge$pStorageId {
  116.     global $gBitUser$gBitSystem;
  117.     $ret FALSE;
  118.  
  119.     if (is_numeric($pStorageId)) {
  120.         $sql "SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` la
  121.                     INNER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON (lf.`file_id`=la.`foreign_id`)
  122.                 WHERE la.`attachment_id` = ?";
  123.         if$row $gBitSystem->mDb->getRow$sqlarray$pStorageId ))) {
  124.             $sourceFile liberty_mime_get_source_file$row );
  125.             if$gBitUser->isAdmin(|| $gBitUser->mUserId == $row['user_id'{
  126.                 iffile_exists$sourceFile )) {
  127.                     // make sure this is a valid storage directory before removing it
  128.                     ifpreg_match'!/users/\d+/\d+/\w+/\d+/.+!'$sourceFile )) {
  129.                         unlink_rdirname$sourceFile ));
  130.                     else {
  131.                         unlink$sourceFile );
  132.                     }
  133.                 }
  134.                 $query "DELETE FROM `".BIT_DB_PREFIX."liberty_files` WHERE `file_id` = ?";
  135.                 $gBitSystem->mDb->query($queryarray($row['foreign_id']) );
  136.                 $ret TRUE;
  137.             }
  138.         }
  139.     }
  140.     return $ret;
  141. }
  142.  
  143. ?>

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