function mime_default_expunge($pAttachmentId) { global $gBitSystem, $gBitUser; $ret = FALSE; if (@BitBase::verifyId($pAttachmentId)) { if ($fileHash = LibertyMime::loadAttachment($pAttachmentId)) { if ($gBitUser->isAdmin() || $gBitUser->mUserId == $fileHash['user_id']) { // make sure this is a valid storage directory before removing it if (!empty($fileHash['source_file']) && ($nuke = LibertyMime::validateStoragePath($fileHash['source_file'])) && is_file($nuke)) { unlink_r(dirname($nuke)); } $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_files` WHERE `file_id` = ?"; $gBitSystem->mDb->query($query, array($fileHash['foreign_id'])); $ret = TRUE; } } } return $ret; }
function mime_default_update(&$pStoreRow) { global $gBitSystem; // this will reset the uploaded file if (BitBase::verifyId($pStoreRow['attachment_id']) && !empty($pStoreRow['upload'])) { if (empty($pStoreRow['dest_branch'])) { $pStoreRow['dest_branch'] = liberty_mime_get_storage_branch(array('attachment_id' => $pStoreRow['attachment_id'])); } if (!empty($pStoreRow['dest_branch']) && !empty($pStoreRow['file_name'])) { // First we remove the old file $path = STORAGE_PKG_PATH . $pStoreRow['dest_branch']; $file = $path . $pStoreRow['file_name']; if (($nuke = LibertyMime::validateStoragePath($path)) && is_dir($nuke)) { if (!empty($pStoreRow['unlink_dir'])) { @unlink_r($path); mkdir($path); } else { @unlink($file); } } // make sure we store the new file in the same place as before $pStoreRow['upload']['dest_branch'] = $pStoreRow['dest_branch']; // if we can create new thumbnails for this file, we remove the old ones first $canThumbFunc = liberty_get_function('can_thumbnail'); if (!empty($canThumbFunc) && $canThumbFunc($pStoreRow['upload']['type'])) { liberty_clear_thumbnails($pStoreRow['upload']); } // Now we process the uploaded file if ($storagePath = liberty_process_upload($pStoreRow['upload'])) { $sql = "UPDATE `" . BIT_DB_PREFIX . "liberty_files` SET `file_name` = ?, `mime_type` = ?, `file_size` = ?, `user_id` = ? WHERE `file_id` = ?"; $gBitSystem->mDb->query($sql, array($pStoreRow['upload']['name'], $pStoreRow['upload']['type'], $pStoreRow['upload']['size'], $pStoreRow['user_id'], $pStoreRow['file_id'])); } // ensure we have the correct guid in the db if (empty($pStoreRow['attachment_plugin_guid'])) { $pStoreRow['attachment_plugin_guid'] = LIBERTY_DEFAULT_MIME_HANDLER; } $gBitSystem->mDb->associateUpdate(BIT_DB_PREFIX . "liberty_attachments", array('attachment_plugin_guid' => $pStoreRow['attachment_plugin_guid']), array('attachment_id' => $pStoreRow['attachment_id'])); } } return TRUE; }
$gBitSystem->confirmDialog($formHash, $msgHash); } else { $feedback['error'] = tra('No valid content id given.'); } } // delete icon if needed if (!empty($_REQUEST['delete_thumbnails'])) { $fileHash['dest_branch'] = dirname($gContent->mInfo['storage_path']) . '/'; liberty_clear_thumbnails($fileHash); $gContent->load(); } // set up everything for re-processing if (!empty($_REQUEST['reprocess_upload'])) { if (!empty($gContent->mInfo['source_file']) && is_file($gContent->mInfo['source_file'])) { // check to see if the file is ok to be deleted if (($nuke = LibertyMime::validateStoragePath($gContent->mInfo['source_file'])) && is_file($nuke)) { // first we need to move the file out of the way $tmpfile = str_replace("//", "/", tempnam(TEMP_PKG_PATH, TREASURY_PKG_NAME)); rename($gContent->mInfo['source_file'], $tmpfile); // fill the upload hash with the file details $_FILES['file']['tmp_name'] = $tmpfile; $_FILES['file']['name'] = $gContent->mInfo['filename']; $_FILES['file']['size'] = $gContent->mInfo['file_size']; $_FILES['file']['type'] = $gContent->mInfo['mime_type']; $_FILES['file']['error'] = 0; $_REQUEST['update_file'] = TRUE; } } else { $feedback['error'] = tra('The file could not be reprocessed. There was a problem locating the original file.'); } }